home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 51 / Amiga Format CD51 (2000-03-10)(Future Publishing)(GB)[!][issue 2000-04].iso / -in_the_mag- / pdselect / blizkick / blizkick.asm < prev    next >
Assembly Source File  |  2000-02-16  |  73KB  |  3,426 lines

  1. ; FILE: Source:BlizKick.ASM          REV: 484 --- BlizKick - the ultimate maprom tool
  2. ; History
  3. ;  1      Running OK!
  4. ;  15     Now BlizKick should work with all Blizzard turbos.
  5. ;  19     Now BlizKick should even support KS 1.0... (?)
  6. ;  25     Added LOCALFAST feature.
  7. ;  31     Added QUICKBOOT feature.
  8. ;  33     Added better Printf.
  9. ;  48     Added Better ROM identification code (checksum).
  10. ;  65     Added "real" cache clear routine.
  11. ;  69     Fixed _seek bug.
  12. ;  71     Fixed KS 1.3 SPEEDROM bug.
  13. ;  81     Replaced "execinit" patch with resident tag.
  14. ;  107    Fix for Blizzard 1260! 1230-IV too!!
  15. ;  111    Added original Kickstart restoration.
  16. ;  114    Implemented KS1.x KS restoration.
  17. ;  115    Improved error messages.
  18. ;  116    Improved MAPROM test and CacheClear routine.
  19. ;  125    Added HOGWAITBLIT feature.
  20. ;  129    Added SetPatch (680x0.library) check.
  21. ;  175    Added MODULE feature.
  22. ;  186    Added EXTRESBUF feature.
  23. ;  210    Added External patches and BKMF_ExtResBuf flag, fixed 1.x ROMTag support.
  24. ;  215    Fixed LOCALFAST feature not to force MEMF_LOCAL or MEMF_KICK!
  25. ;  220    Fixed KS 1.x ROMTag support.
  26. ;  225    Added special handling for 1230-IV and 1260. Fixed FORCE.
  27. ;  240    Removed need to be run before SetPatch on 1260 systems.
  28. ;  248    Can be used with Enforcer, CPU FASTROM, VMM etc.
  29. ;  257    Improved 040/060 cache flushing code. BlizKick release 1.6.
  30. ;  266    Fixed bug in 040/060 MMU test code.
  31. ;  276    Added XPK support.
  32. ;  277    Modified to work better with PowerPC... :)
  33. ;  279    Added better (Old)OpenLibrary code. Removed FindName() things.
  34. ;  289    Fixed XPK support.
  35. ;  293    Now will set memory node name if null.
  36. ;  300    Fixed EXTRESBUF.
  37. ;  302    Fixed negative return code bug.
  38. ;  307    Added ROM address validity test.
  39. ;  311    Fixed BLIZZARD 2060 code.
  40. ;  313    Fixed one terrible bug from B2060 code.
  41. ;  328    Fixing EXTRESBUF...
  42. ;  332    Finished! Now it should work with 1260, 2040 and 2060.
  43. ;  338    DOES work on 1260. Fixed one minor bug. SoftSCSI module doesn't work.
  44. ;  340    Added memheader move code to LOCALFAST. -> Speed AllocMem()
  45. ;  343    Fixed reset code!
  46. ;  344    Allowed BlizKick to kick same kickfile and rom chip version.
  47. ;  348    Fixed .testblizppcrunnommu. Added pseudofile (*) feature.
  48. ;  353    Added LastPatches (fix for MEMF_REVERSE svstack, etc.)
  49. ;  361    Fixed svstack trash, disabled SVSTACKTRASH.
  50. ;  377    Added QUIET switch, fixed LastPatches, KS 33.180 works now!
  51. ;  388    Got KS 33.180 finally work 100%.
  52. ;  389    Added handling for BKMODPATH env variable.
  53. ;  399    Improved HOGWAITBLIT.
  54. ;  400    Found out that 2040 and 2060 boards are almost identical.
  55. ;  403    Fixed reset code to *disable* caches.
  56. ;  404    1.11ß1: Trying to get EXTRESBUF into fastmem.
  57. ;  412    Did it. Seems to work 100%.
  58. ;  415    Fixed MAPROM test. Now should detect if MAPROM not set.
  59. ;  416    Disabled SUPERVISOR_NOREVERSE from LastPatches.
  60. ;  421    Added support for (A4000?) CPU Cards.
  61. ;  425    Now KS 1.x are only patched if they're original versions. This should
  62. ;         prevent problems with some patches 1.x ROM images.
  63. ;  426    Fixed bug in ROM image validation test.
  64. ;  427    9th Dec 1997: ARGH! Wrote nice CPUCard support but forgot to enable
  65. ;         it!!! ;-)
  66. ;  429    Added support for Cyberstorm PPC and MKIII. Now should work at least
  67. ;         with CBM CPU Cards, Cyberstorm MKI, MKIII and PPC.
  68. ;  439    Separated A1200 and other model's check routines. Hopefully fixed CS
  69. ;         MKIII/PPC support. Added CS MKII support. Now CPUCARD is only meant to
  70. ;         be used with CS MKI & compatible.
  71. ;  442    Fixed few typos etc.
  72. ;  443    Fixed stupid BUG from CS support... THANKS DUKEN!! =)
  73. ;  444    Had mixed 20x0 and CS MK II product IDs... doh! Thanks shido at #amiga!
  74. ;  445    Fixed some Lock bugs.
  75. ;  446    13th May 1998 Made the source public in hope someone would continue the
  76. ;         development.
  77. ;  450    6th July 1998 Added Blizzard PPC support.
  78. ;  458    8th July 1998 Fixed Blizzard PPC and CS MKII support (I hope).
  79. ;  459    17th July 1998 Fixed stupid bug from CS MKII support.
  80. ;  461    4th October 1998 Finally fixed the blizz ppc bug. hehe.
  81. ;  462    6th October 1998 Fixed support for old KS.
  82. ;  463    9th October 1998 Fixed MK2 bug. Ta ChaoZer.
  83. ;  464    13th October 1998 Another MK2 fix <sigh>. Ta ChaoZer.
  84. ;  467    3rd November 1998 Disabled rom checksum disable in SPEEDROM.
  85. ;  468    24th January 1999 Fixed stupid blizzppc (and probably CSPPC too)
  86. ;         bug, blizzppc/csppc kernel overwrote EXTRES buffer. Now allocates
  87. ;         1mb extra memory. froze 1.18.
  88. ;  469    7th November 1999 Made BlizKick use fastmem hunks again. Finally
  89. ;         made it possible to `FORCE-after-maprom-is-already-active' and remove
  90. ;         maprom for Blizzard PPC.
  91. ;  470    Implemented new straightforward method to solve BKMODPATH variable
  92. ;         in DoPlanting routine.
  93. ;  471    Doesn't Delay(25) if QUIET is specified.
  94. ;  472    Added 040/060 move16 optimized copymem256.
  95. ;  473    Sped up FindResident and resident module reconnect. froze 1.19.
  96. ;  474    7th Jan 2000: Bumped revision strings to 1.20.
  97. ;  475    8th Jan 2000: Fixed major memory loss on extresbuf Deallocate on error
  98. ;         condition. Also that Deallocate() call wasn't called in Forbid state.
  99. ;  476    9th Jan 2000: New feature: you can give *any* loadsegable executable
  100. ;         as module. Resident modules inside will be initialized. Cool. Renders
  101. ;         SCSIDEV43 module obsolete, just give devs:scsi43.device as one module!
  102. ;         You can also give l:fastfilesystem etc! wooow, this is WAY too cool. :)
  103. ;         This required a change in the internal way of handling EXTRES buffer
  104. ;         + some new InternalLoadSeg code.
  105. ;  477    Now uses move.l an,an as nop when possible. FindResident bugged, it
  106. ;         scanned ROM first, then EXTRES buffer. Fixed to be opposite.
  107. ;  478    Added mmu.library support to getmmu and runnommu routine. This is a
  108. ;         "good thing"(TM).
  109. ;  479    14th Jan 2000: LOCALFAST and QUICKBOOT are now finally gone. Arguments
  110. ;         are there, but do nothing. Now the good news: Finally cleaned up the
  111. ;         code, and changed EXTRES buffer attaching to ROM such way it finally
  112. ;         works everytime on blizzppc. Yes! Added new argument SANITY/K/N to
  113. ;         specify sanity added to EXTRES buffer allocation in kbytes. PoolMem
  114. ;         could have fucked BlizKick in several ways, it changes MemHeaders on
  115. ;         the fly... Fixed. froze 1.20.
  116. ;  480    17th Jan 2000: *MAJOR BUG*: move16 could have easily got source
  117. ;         aligned by only 8 causing copy source shifted by 8 bytes -> non
  118. ;         working rom image. *THIS* has caused all these weird crashed with
  119. ;         different EXTRESBUF sizes. Me & my ultrafast copyloop. Duh! :(
  120. ;         Now uses *only* movem copy.
  121. ;  481    Wrote separate LocalFast module so removed ARG_LOCALFAST completely.
  122. ;         exe module support didn't set error code properly when out of EXTRES
  123. ;         buffer memory. Accidently called dos.library/Open for _gettc when
  124. ;         exec.library/Supervisor should have been called. Fun thing is that
  125. ;         this had so side effects. :) froze 1.21.
  126. ;  482    29th Jan: Fixed some nastiness from Blizzard 1230 maprom .testcode,
  127. ;         dunno if this fixes anything, but anyway it was bugged. mmu.library
  128. ;         getmmu was bugged: it always thought machine had 030 compatible MMU,
  129. ;         this didn't cause any problems though, but was wrong. Oops, stupid
  130. ;         bug in MK2 support, blo instead of bhi. Also 20x0 support could have
  131. ;         been affected.
  132. ;  483    31th Jan: removed CPU Card test code, I think it prevented it from
  133. ;         working, I hope.
  134. ;  484    3rd Feb: CS MK II works now, but BlizKick didn't recognize if it was
  135. ;         run before. Tweaked check code to run MMU disabled, see _checkactive.
  136. ;
  137.  
  138.  
  139. ;DEBUGMODE    EQU    1        ;don't clone code
  140.  
  141. ;
  142. ; I seriously doubt if this source code is useful for anything else.
  143. ; Hairy code everywhere, this one is really a bitch to maintain...
  144. ;
  145.  
  146. ; TODO (err, not never, maybe, huh)
  147. ; o BootControl module. Requested by several users. Also RebootFix
  148. ;   clashes with BootControl I think.
  149. ; o Fix CS MK I, II, and A4000 CPU card support, if only possible.
  150. ; o Fix problems with some B-1230 systems. At least -I and -II don't
  151. ;   seem to work.
  152. ;
  153. ; o ROM checksum (restore orig rom if bad)
  154. ; o IDEFix97 module (replacing LoadIDE)
  155. ; o OxyPatcher module (maybe)
  156. ; o possibility to get commandline arguments from a file
  157. ;   (can be emulated with `BlizKick ? <cmd_file')
  158. ; o module memory requirements inside the module itself ('$LEN: 280' ?)
  159. ; o SoftSCSI for Blizzard 20x0. Only if I had the information needed...
  160. ;
  161.  
  162. USE_STD_INCLUDES    SET    1
  163.     IFNE    USE_STD_INCLUDES
  164.     MACHINE    MC68040
  165.     include    "exec/types.i"
  166.     include    "exec/nodes.i"
  167.     include    "exec/libraries.i"
  168.     include    "exec/memory.i"
  169.     include    "exec/execbase.i"
  170.     include    "exec/resident.i"
  171.     include    "exec/alerts.i"
  172.     include    "exec/semaphores.i"
  173.     include    "dos/dos.i"
  174.     include    "exec/exec_lib.i"
  175.     include    "dos/dos_lib.i"
  176.     include    "graphics/gfxbase.i"
  177.     include    "graphics/graphics_lib.i"
  178. call    MACRO
  179.     jsr    (_LVO\1,a6)
  180.     ENDM
  181.     ELSE
  182.     include    "Devpac:Gen.gs"
  183.     ENDC
  184.     include    "dos/dosextens.i"
  185.     include    "libraries/configvars.i"
  186.     include    "libraries/expansion_lib.i"
  187.     include    "hardware/dmabits.i"
  188.     include    "hardware/custom.i"
  189.  
  190.     include    "libraries/xpk.i"    ; from xpk_dev
  191.  
  192.     include    "blizkickmodule.i"
  193.  
  194.  
  195. ; mmu.library LVOs
  196.     IFND    _LVOGetMMUType
  197. _LVOGetMMUType    EQU    -$36
  198. _LVOWithoutMMU    EQU    -$10E
  199.     ENDC
  200.  
  201.     IFND    MUTYPE_NONE
  202. MUTYPE_NONE     equ     0
  203. MUTYPE_68851    equ     '2'
  204. MUTYPE_68030    equ     '3'
  205. MUTYPE_68040    equ     '4'
  206. MUTYPE_68060    equ     '6'
  207.     ENDC
  208.  
  209. ; PoolMem uses this to indicate small pool MemHeader.
  210. ; We don't want to get EXTRES buffer memory from such mem...
  211.     BITDEF    MEM,POOLMEM,4
  212.  
  213.  
  214. ARG_KICKFILE    EQU    0
  215. ARG_MODULE    EQU    4
  216. ARG_EXTRESBUF    EQU    8
  217. ARG_SANITY    EQU    12
  218. ARG_FORCE    EQU    16
  219. ARG_QUICKBOOT    EQU    20
  220. ARG_SPEEDROM    EQU    24
  221. ARG_HOGWAITBLIT    EQU    28
  222. ARG_CPUCARD    EQU    32
  223. ARG_QUIET    EQU    36
  224.  
  225. BLIZPROD    EQU    $2140
  226. ROMSUMOFFS    EQU    -$18
  227. ROMSIZEOFFS    EQU    -$14
  228. IDOFFS    EQU    -$10
  229. BLIZKICK_ID    EQU    'BlzK'
  230. DEF_SANITY    EQU    32        ;default allocation sanity buffer, 32k
  231.  
  232. KEEP_CHECKSUM    EQU    1        ;don't disable rom checksum
  233. NEW_ENV_METHOD    EQU    1        ;use new BKMODPATH solve routine
  234.  
  235. CACHEFLUSH040    MACRO
  236.     dc.w    $F478        ; CPUSHA BC    flush the data into memory
  237.     dc.w    $4E71        ; nop
  238.     ENDM
  239.  
  240. FULLFLUSH040    MACRO
  241.     dc.w    $F478        ; CPUSHA BC    flush the data into memory
  242.     dc.w    $F518        ; PFLUSHA    flush the address translation cache
  243.     dc.w    $4E71        ; nop
  244.     ENDM
  245.  
  246. ;;    dc.w    $F4F8        ; CPUSHA DC    flush the data cache into memory
  247.  
  248.  
  249.     SECTION    CODE,CODE
  250.  
  251. Main    move.l    a0,a2
  252.     move.l    d0,d2
  253.     moveq    #RETURN_FAIL,d7
  254.     move.l    (4).w,a6
  255.  
  256.     lea    (mmuname,pc),a1
  257.     moveq    #41,d0
  258.     bsr    OpenLib
  259.     lea    (_mmubase,pc),a0
  260.     move.l    d0,(a0)
  261.  
  262.     lea    (_ExecBase,pc),a0
  263.     move.l    a6,(a0)
  264.     lea    (_AttnFlags,pc),a0
  265.     move.w    (AttnFlags,a6),(a0)
  266.  
  267.     IFGT    0
  268.     btst    #AFB_68040,(_AttnFlags+1,pc)
  269.     bne.b    .has_040
  270.     lea    (copymem256,pc),a0
  271.     move.w    #$6000|(copymem256_000-copymem256-2),(a0)
  272. .has_040
  273.     ENDC
  274.  
  275.     IFD    DEBUGMODE
  276.     bsr    CacheClearOS
  277.     ELSE
  278.     move.l    #CODE_SIZEOF,d0
  279.     move.l    #MEMF_PUBLIC,d1
  280.     call    AllocMem
  281.     lea    (_Self,pc),a0
  282.     move.l    d0,(a0)
  283.     beq    .exit
  284.  
  285.     move.l    d0,a1
  286.     pea    (.jmpdest-Main,a1)
  287.     pea    (CacheClearOS,pc)
  288.     lea    (Main,pc),a0
  289.     move.l    #CODE_SIZEOF,d0
  290.     jmp    (_LVOCopyMemQuick,a6)
  291. .jmpdest
  292.     ENDC
  293.  
  294.     lea    (DosName,pc),a1
  295.     moveq    #33,d0
  296.     bsr    OpenLib
  297.     move.l    d0,d6
  298.     beq    .exit
  299.     move.l    d0,a6
  300.  
  301.     moveq    #0,d4            Set default!!
  302.  
  303.     cmp.w    #37,(LIB_VERSION,a6)
  304.     shs    d5
  305.  
  306.     bsr    getmmu
  307.     lea    (_mmuflag,pc),a0
  308.     move.b    d0,(a0)
  309.     beq.b    .nommu
  310.  
  311.     btst    #AFB_68040,(_AttnFlags+1,pc)
  312.     beq.b    .nommu
  313.     ; oops, used to call dos.library/Open() instead ;)
  314.     move.l    (_ExecBase,pc),a6
  315.     lea    (_gettc,pc),a5
  316.     call    Supervisor
  317.     lea    (_tc,pc),a0
  318.     move.l    d0,(a0)
  319.     move.l    d6,a6
  320. .nommu
  321.  
  322.     lea    (_Array,pc),a3
  323.     tst.b    d5
  324.     bne.b    .ks20
  325.     clr.l    -1(a2,d2.l)
  326.     subq.l    #1,d2
  327.     beq.b    .do            RESTORE!
  328.     move.l    a2,(a3)
  329.     lea    (_13Help,pc),a0
  330.     cmp.b    #'?',(a2)
  331.     bne.b    .do
  332.     subq.l    #1,d2
  333.     beq    .printmsgexit
  334.     bra.b    .do
  335. .ks20    lea    (_Template,pc),a0
  336.     move.l    a0,d1
  337.     move.l    a3,d2
  338.     moveq    #0,d3
  339.     call    ReadArgs
  340.     move.l    d0,d4
  341.     beq    .badargs
  342.  
  343. .do
  344.     lea    (_Quiet,pc),a0
  345.     move.l    (ARG_QUIET,a3),(a0)
  346.  
  347.     tst.l    (ARG_CPUCARD,a3)
  348.     beq.b    .no_cpucard
  349.     IFGT    1
  350.     lea    (_CPUCard,pc),a0
  351.     st    (a0)
  352.     bra.b    .has_cpucard
  353.     ELSE
  354.     bsr    CheckCPUCard
  355.     lea    (_CPUCard,pc),a0
  356.     move.b    d0,(a0)
  357.     bne.b    .has_cpucard
  358.     lea    (NoCPUCard,pc),a0
  359.     bra.b    .printmsgexit
  360.     ENDC
  361. .no_cpucard
  362.  
  363.     bsr    TestBliz
  364.     lea    (RequiresBliz,pc),a0
  365.     lea    (_BlizROM,pc),a1
  366.     move.l    d0,(a1)
  367.     beq.b    .printmsgexit
  368. .has_cpucard
  369.  
  370.     movem.l    d4-d6/a6,-(sp)
  371.     moveq    #RETURN_ERROR,d7
  372.     lea    (Messu,pc),a0
  373.     bsr    _PrintHeaderf
  374.     bsr    _HeadMain
  375.     movem.l    (sp)+,d4-d6/a6
  376.  
  377. .freeargs    tst.b    d5
  378.     beq.b    .closedos
  379.     move.l    d4,d1
  380.     call    FreeArgs
  381. .closedos    move.l    d6,a1
  382.     move.l    (_ExecBase,pc),a6
  383.     call    CloseLibrary
  384. .exit
  385.  
  386.     move.l    (_mmubase,pc),d0
  387.     beq.b    .nommulib
  388.     move.l    d0,a1
  389.     call    CloseLibrary
  390. .nommulib
  391.     move.l    (_Self,pc),d0
  392.     beq.b    .nocopy
  393.     move.l    d0,a1
  394.     move.l    #CODE_SIZEOF,d0
  395.     call    Forbid            Make sure we have time to execute
  396.     call    FreeMem            the rest...
  397. .nocopy    move.l    d7,d0
  398.     rts
  399.  
  400. .printmsgexit    bsr    _PrintHeaderf
  401.     bra.b    .freeargs
  402.  
  403. .badargs    bsr.b    _PrintFault        IN: d5=kickflag, d6=dosbase
  404.     bra.b    .closedos
  405.  
  406.  
  407. ;  IN: d5=kickflag, d6=dosbase
  408. ; OUT: Fault printed
  409. _PrintFault    movem.l    d0-d2/a0-a1/a6,-(sp)
  410.     move.l    (_Quiet,pc),d0
  411.     bne.b    .exit
  412.     move.l    d6,a6
  413.     call    IoErr
  414.     tst.b    d5
  415.     beq.b    .oldie
  416.     move.l    d0,d1
  417.     moveq    #0,d2
  418.     call    PrintFault
  419. .exit    movem.l    (sp)+,d0-d2/a0-a1/a6
  420.     rts
  421.  
  422. .oldie    move.l    d0,-(sp)
  423.     beq.b    .noerr
  424.     lea    (_ks13error,pc),a0
  425.     move.l    sp,a1
  426.     bsr    _Printf
  427. .noerr    addq.l    #4,sp
  428.     bra.b    .exit
  429.  
  430.  
  431. ;  IN: A0=FmtString, A1=Array, a2=Buffer
  432. ; OUT: Formatted text
  433. _Sprintf    movem.l    d0-d1/a0-a3/a6,-(sp)
  434.     move.l    a2,a3
  435.     lea    (.putchar,pc),a2
  436.     move.l    (_ExecBase,pc),a6
  437.     call    RawDoFmt
  438.     movem.l    (sp)+,d0-d1/a0-a3/a6
  439.     rts
  440. .putchar    move.b    d0,(a3)+
  441.     rts
  442.  
  443.  
  444. ;  IN: A0=FmtString, A1=Array, d6=dosbase
  445. ; OUT: Printed text, including program info header
  446. _PrintHeaderf    movem.l    d0-d1/a0-a2/a6,-(sp)
  447.     move.l    (_ExecBase,pc),a6
  448.     move.l    #$10000,d0        ; Allocate 64k buffer
  449.     moveq    #MEMF_ANY,d1
  450.     call    AllocMem
  451.     move.l    d0,-(sp)
  452.     beq.b    .nomem
  453.     movem.l    (3*4,sp),a0-a1
  454.     move.l    (sp),a2
  455.     bsr.b    _Sprintf
  456.     pea    (_Copyright,pc)
  457.     pea    (_Version,pc)
  458.     lea    (.header,pc),a0
  459.     move.l    sp,a1
  460.     bsr.b    _Printf
  461.     addq.l    #8,sp
  462. .nomem    move.l    (sp)+,d0
  463.     beq.b    .exit
  464.     move.l    d0,a1
  465.     move.l    #$10000,d0
  466.     call    FreeMem
  467. .exit    movem.l    (sp)+,d0-d1/a0-a2/a6
  468.     rts
  469. .header    dc.b    $9B,'1;32m%s',$9B,'31m %s.',$9B,'0m',10
  470.     dc.b    '%s',0
  471.     CNOP    0,2
  472.  
  473.  
  474.     STRUCTURE pf_data,0
  475.     APTR    pfd_DosBase
  476.     APTR    pfd_Count
  477.     STRUCT    pfd_Buffer,256
  478.     LABEL    pf_data_SIZEOF
  479.  
  480.     CNOP    0,4
  481. ;;_OutputFH    dc.l    0
  482. ;  IN: A0=FmtString, A1=Array (may be 0), d6=dosbase
  483. ; OUT: Printed text
  484. _Printf
  485. Printf    movem.l    a0-a3/a6/d0-d3,-(sp)
  486.     move.l    (_Quiet,pc),d0
  487.     bne.b    .exit
  488.     lea    (-pf_data_SIZEOF,sp),sp
  489.     move.l    sp,a3
  490.     move.l    d6,(a3)+
  491.     clr.l    (a3)+
  492.     lea    (.newchar,pc),a2
  493.     move.l    (_ExecBase,pc),a6
  494.     call    RawDoFmt
  495.     move.l    d6,a6
  496.     IFD    _OutputFH
  497.     move.l    _OutputFH,d1
  498.     ELSE
  499.     call    Output
  500.     move.l    d0,d1
  501.     ENDC
  502.     move.l    a3,d2
  503.     move.l    (-4,a3),d3
  504.     call    Write
  505.     lea    (pf_data_SIZEOF,sp),sp
  506. .exit    movem.l    (sp)+,a0-a3/a6/d0-d3
  507.     rts
  508. .newchar    movem.l    d0-d3/a0-a1/a3/a6,-(sp)
  509.     move.l    a3,d2                for Write()
  510.     move.l    -(a3),d1
  511.     move.b    d0,4(a3,d1.l)
  512.     addq.b    #1,d1
  513.     move.l    d1,(a3)
  514.     bne.b    .dont_print
  515.     move.l    -(a3),a6
  516.     IFD    _OutputFH
  517.     move.l    _OutputFH,d1
  518.     ELSE
  519.     call    Output
  520.     move.l    d0,d1
  521.     ENDC
  522.     move.l    #256,d3
  523.     call    Write
  524. .dont_print    movem.l    (sp)+,d0-d3/a0-a1/a3/a6
  525.     rts
  526.  
  527.  
  528. ;  IN: d6=dosbase, should remain if you're going to call internal _xxx functions
  529. ;      a3=paramarray, is zero if null template, scratch
  530. ;      a6=dosbase, scratch
  531. ; OUT: d7=return code
  532. _HeadMain    tst.l    (a3)            (ARG_KICKFILE,a3)
  533.     bne.b    .norestore
  534.     lea    (_restore,pc),a0
  535.     bsr    runnommu
  536.     movem.l    (_regtemp,pc),d3/a4    preserves condition codes!
  537.     bne    KickSys
  538.  
  539.     lea    (NoRem,pc),a0
  540.     bra    _Printf
  541. .norestore
  542.     moveq    #0,d1            !!
  543.     bsr    SetIoErr
  544.  
  545.     lea    (_checkactive,pc),a0
  546.     bsr    runnommu
  547.     move.b    d0,d2            keep this flag for a while
  548.  
  549.     tst.l    (ARG_FORCE,a3)
  550.     bne.b    .force1
  551.  
  552.     moveq    #RETURN_WARN,d7
  553.     tst.b    d2
  554.     beq    .exit            Already kicked!
  555.  
  556.     moveq    #RETURN_ERROR,d7
  557.  
  558. .force1    move.l    (a3),a0            (ARG_KICKFILE,a3),a0
  559.     cmp.b    #'*',(a0)
  560.     bne.b    .not_pseudofile
  561.     tst.b    (1,a0)
  562.     bne.b    .not_pseudofile
  563.  
  564.     ; Handle "*" -file:
  565.     tst.b    d2            Test for kicked ROM.
  566.     beq    .exit            Already kicked!
  567.     lea    $01000000+IDOFFS,a4    Will fail if kicked previously!
  568.     move.l    -(a4),d3        a4=$01000000+ROMSIZEOFFS
  569.     move.l    d3,d0
  570.     moveq    #MEMF_PUBLIC,d1
  571.     move.l    (_ExecBase,pc),a6
  572.     call    AllocMem
  573.     tst.l    d0
  574.     beq    .exit
  575.     move.l    a4,a0
  576.     sub.l    d3,a0
  577.     add.w    #-ROMSIZEOFFS,a0
  578.     move.l    d0,a4
  579.     move.l    a4,a1
  580.     move.l    d3,d0
  581.     call    CopyMemQuick
  582.     move.l    d3,d1
  583.     move.l    d3,d4
  584.     bra.b    .cont_pseudo
  585.  
  586. .not_pseudofile
  587.     bsr    XPKLoad
  588.     beq    .exit
  589.     move.l    a1,a4
  590.     move.l    d1,d3
  591.     move.l    d0,d4
  592.  
  593. .cont_pseudo    and.l    #$FFF3FFFF,d1        256K or 512K ROM
  594.     bne    .free
  595.     cmp.l    #$00080000,d3
  596.     bhi    .free
  597.     lea    ROMSUMOFFS(a4,d3.l),a5
  598.     cmp.l    (4,a5),d3        Compare to romsize
  599.     bne    .free
  600.  
  601.     move.l    (a4),d2
  602.     and.l    #$FFF8FFFF,d2
  603.     cmp.l    #$11104EF9,d2
  604.     bne    .free
  605.     move.l    (4,a4),d2        Test for relocated ROM
  606.     add.l    d3,d2
  607.     swap    d2
  608.     cmp.w    #$0100,d2
  609.     bne    .free
  610.  
  611.     move.l    a4,a0            Get original ROM checksum
  612.     move.l    d3,d0
  613.     bsr    ROMReSum
  614.     lea    (_OrigSum,pc),a0
  615.     move.l    d0,(a0)
  616.  
  617.     movem.l    ($C,a4),d0/d1        Fix for old KS
  618.     addq.l    #1,d0
  619.     bne.b    .nofix
  620.     move.l    d1,($C,a4)
  621. .nofix
  622.     tst.l    (ARG_FORCE,a3)
  623.     bne.b    .force2
  624.  
  625.     moveq    #RETURN_WARN,d7
  626.     lea    $01000000,a1
  627.     move.l    a1,a0
  628.     sub.l    (ROMSIZEOFFS,a0),a0
  629.     move.l    ($C,a0),d0        Test for different version.
  630.     cmp.l    ($C,a4),d0
  631.     bne.b    .kick
  632.  
  633.     cmp.l    #BLIZKICK_ID,(8,a5)    Test for kicked file.
  634.     beq.b    .free
  635.  
  636. .kick    moveq    #RETURN_ERROR,d7
  637. .force2
  638.     move.l    (_Quiet,pc),d0
  639.     bne.b    .no_output
  640.     lea    (Messu2,pc),a0
  641.     lea    ($C,a4),a1
  642.     bsr    _Printf
  643.     move.l    d6,a6
  644.     moveq    #25,d1
  645.     call    Delay
  646. .no_output
  647.     bsr.b    GoForIt
  648.  
  649. .free    move.l    (_ExecBase,pc),a6
  650.     move.l    a4,a1
  651.     move.l    d4,d0
  652.     call    FreeMem
  653.  
  654. .exit    tst.l    d7
  655.     bmi.b    .nexitok
  656.     beq.b    .exitok
  657.     bsr    _PrintFault        IN: d5=kickflag, d6=dosbase
  658.     lea    (Already,pc),a0
  659.     cmp.w    #RETURN_WARN,d7
  660.     beq.b    .thiserr
  661.     lea    (CouldNotKick,pc),a0
  662. .thiserr    move.l    a3,a1
  663.     bra    _Printf
  664. .nexitok    neg.l    d7            result IN d7!!
  665. .exitok    rts
  666.  
  667.  
  668.  
  669. GoForIt    ;illegal
  670.  
  671.     neg.l    d7
  672.     move.l    (_ExecBase,pc),a6
  673.  
  674.     move.l    (ARG_EXTRESBUF,a3),d0
  675.     beq.b    .no_extbuf
  676.     move.l    d0,a0
  677.     move.l    (a0),d1
  678.  
  679.     move.l    #DEF_SANITY,d2
  680.     move.l    (ARG_SANITY,a3),d0
  681.     beq.b    .nosanity
  682.     move.l    d0,a0
  683.     move.l    (a0),d2
  684. .nosanity    lsl.l    #8,d2
  685.     lsl.l    #2,d2            *1024
  686.  
  687.     move.l    a4,a0
  688.     move.l    d3,d0
  689.     bsr    ExtResBuf
  690.     bne.b    .got_extbuf
  691.     bsr    _PrintFault        IN: d5=kickflag, d6=dosbase
  692.     bra.b    .fail
  693. .got_extbuf
  694. .no_extbuf
  695.     tst.l    (ARG_HOGWAITBLIT,a3)
  696.     beq.b    .no_agawblit
  697.     move.l    a4,a0
  698.     move.l    d3,d0
  699.     bsr    PutHogWaitBlit
  700. .no_agawblit
  701.     move.l    a4,a0
  702.     move.l    d3,d0
  703.     bsr    DoPlanting
  704.     beq.b    .fail
  705.  
  706.     tst.l    (ARG_SPEEDROM,a3)
  707.     beq.b    .no_patch2
  708.     move.l    a4,a0
  709.     move.l    d3,d0
  710.     bsr    SpeedROM
  711. .no_patch2
  712.  
  713.     move.l    a4,a0
  714.     move.l    d3,d0
  715.     bsr    LastPatches
  716.  
  717.  
  718.     move.l    #BLIZKICK_ID,IDOFFS(a4,d3.l)
  719.     move.l    a4,a0
  720.     move.l    d3,d0
  721.     bsr.b    ROMReSum
  722.     move.l    d0,ROMSUMOFFS(a4,d3.l)
  723.     bsr    CacheClearOS
  724.  
  725.     bsr    KickSys
  726. .fail
  727.  
  728. ;;    bra    FreeExtResBuf
  729.  
  730. ;  IN: a6=execbase
  731. ; OUT: d0/d1/a0/a1 trashed
  732. FreeExtResBuf
  733.     move.l    (_erh_freeaddr,pc),d0
  734.     beq.b    .xit
  735.     move.l    d0,a1
  736.     move.b    (_MemHeaderFlag,pc),d1
  737.     beq.b    .xit
  738.     call    Forbid
  739.     lea    (_memhead,pc),a0
  740.     bsr    FindMemHeader
  741.     beq.b    .cantfind
  742.     move.l    (_erh_alloclen,pc),d0
  743.     call    Deallocate
  744. .cantfind    call    Permit
  745.     lea    (_erh_freeaddr,pc),a0
  746.     clr.l    (a0)
  747. .xit    rts
  748.  
  749.  
  750. ROMReSum    move.l    d0,d1
  751.     lsr.l    #2,d1
  752.     move.l    ROMSUMOFFS(a0,d0.l),d0
  753.     not.l    d0
  754. .loop    add.l    (a0)+,d0
  755.     bcc.b    .skip
  756.     addq.l    #1,d0
  757. .skip    subq.l    #1,d1
  758.     bne.b    .loop
  759.     not.l    d0
  760.     rts
  761.  
  762.  
  763.  
  764. _checkactive    cmp.l    #BLIZKICK_ID,$01000000+IDOFFS Test for kicked ROM.
  765.     sne    d0
  766.     rts
  767.  
  768.  
  769. _restore    cmp.l    #BLIZKICK_ID,$01000000+IDOFFS    Test for kicked ROM.
  770.     bne.b    .exitrts
  771.     lea    $0B80000,a4        Magic address!
  772.     move.l    (ROMSIZEOFFS,a4),d3
  773.     move.l    d3,d0
  774.     and.l    #$FFF3FFFF,d0        256K or 512K ROM
  775.     bne.b    .exitrts
  776.     cmp.l    #$00080000,d3
  777.     bhi.b    .exitrts
  778.     sub.l    d3,a4
  779.  
  780.     move.l    (a4),d0
  781.     and.l    #$FFF8FFFF,d0
  782.     cmp.l    #$11104EF9,d0
  783.     bne.b    .exitrts
  784.  
  785.     lea    (_regtemp,pc),a0
  786.     movem.l    d3/a4,(a0)
  787.     moveq    #1,d0
  788.     rts
  789. .exitrts    moveq    #0,d0
  790.     rts
  791.  
  792.  
  793. ;  IN: -
  794. ; OUT: d0=0 if no mmu, -1 if 040/060 mmu, 1 if 030/851 MMU.
  795. getmmu    movem.l    d1-a6,-(sp)
  796.     moveq    #0,d7
  797.  
  798.     move.l    (_mmubase,pc),d0
  799.     bne.b    .use_mmulib
  800.  
  801.     move.l    (_ExecBase,pc),a6
  802.     move.w    (AttnFlags,a6),d0
  803.     btst    #AFB_68020,d0
  804.     beq.b    .exit
  805.     cmp.w    #37,(LIB_VERSION,a6)
  806.     blo.b    .oldtest
  807.  
  808.     moveq    #-1,d7
  809.     lea    (.test040plus,pc),a5
  810.     btst    #AFB_68040,d0
  811.     bne.b    .test
  812. .oldtest    moveq    #1,d7
  813.     lea    (.test020plus,pc),a5
  814.  
  815. .test    call    Disable
  816.     call    Supervisor
  817.     call    Enable
  818.  
  819. .exit    move.l    d7,d0
  820.     movem.l    (sp)+,d1-a6
  821.     rts
  822.  
  823.  
  824. .use_mmulib    move.l    d0,a6    
  825.     call    GetMMUType
  826.     move.b    d0,d7
  827.     beq.b    .exit
  828.  
  829.     moveq    #-1,d7
  830.     cmp.b    #MUTYPE_68040,d0    040 MMU
  831.     beq.b    .exit
  832.     cmp.b    #MUTYPE_68060,d0    060 MMU
  833.     beq.b    .exit
  834.  
  835.     moveq    #1,d7            851/030 MMU
  836.     bra.b    .exit
  837.  
  838.  
  839. .test040plus    or.w    #$700,sr        Disable interrupts.
  840.     movec    vbr,a0            Get VBR
  841.     move.l    ($10,a0),-(sp)        Save Illegal Instruction vector
  842.     move.l    a0,-(sp)        Save VBR
  843.     lea    (.illegal040,pc),a1
  844.     move.l    a1,($10,a0)
  845.  
  846.     bsr    _fullflush040
  847.     movec    tc,d0            $4e7a0003    Test some "common" MMU regs:
  848.     movec    urp,d1            $4e7a1806    Test 040/060 MMU only reg!!
  849.     movec    srp,d1            $4e7a1807    Test 040/060 MMU only reg!!
  850.     nop
  851.     nop
  852. .exit040
  853.     move.l    (sp)+,a0
  854.     move.l    (sp)+,($10,a0)        Restore Illegal Instruction vector
  855.     bsr    _fullflush040
  856.     nop
  857.     rte
  858.  
  859.  
  860.     CNOP    0,4
  861. .illegal040    moveq    #0,d7
  862.     lea    (.exit040,pc),a0
  863.     move.l    a0,(2,sp)
  864.     bsr    _fullflush040
  865.     nop
  866.     rte
  867.  
  868.  
  869. .test020plus    or.w    #$700,sr        Disable interrupts.
  870.  
  871.     movec    vbr,a0            Get VBR
  872.     move.l    ($10,a0),-(sp)        Save Illegal Instruction vector
  873.     move.l    ($2C,a0),-(sp)        Save F-Line Emul vector
  874.     move.l    ($E0,a0),-(sp)        Save MMU Config Error vector
  875.     move.l    ($E4,a0),-(sp)        Save MMU Illegal Operation Error vector
  876.     move.l    ($E8,a0),-(sp)        Save MMU Access Level Violation Error vector
  877.     move.l    a0,-(sp)        Save VBR
  878.  
  879.     lea    (.mmuinstfailure,pc),a1
  880.     move.l    a1,($10,a0)
  881.     move.l    a1,($2C,a0)
  882.     move.l    a1,($E0,a0)
  883.     move.l    a1,($E4,a0)
  884.     move.l    a1,($E8,a0)
  885.  
  886.     bsr    _flush020
  887.  
  888.     subq.l    #4,sp            Try to get TC
  889.     dc.w    $F017,$4200        pmove.l tc,(sp)
  890. .exitsuper
  891.     addq.l    #4,sp
  892.     move.l    (sp)+,a0        Restore VBR
  893.     move.l    (sp)+,($E8,a0)        Restore MMU Access Level Violation Error vector
  894.     move.l    (sp)+,($E4,a0)        Restore MMU Illegal Operation vector
  895.     move.l    (sp)+,($E0,a0)        Restore MMU Config Error vector
  896.     move.l    (sp)+,($2C,a0)        Restore F-Line Emul vector
  897.     move.l    (sp)+,($10,a0)        Restore Illegal...
  898. .exitall    bsr.b    _flush020
  899.     nop
  900.     rte
  901.  
  902. .mmuinstfailure    moveq    #0,d7
  903.     lea    (.exitsuper,pc),a0    Invalid mmu instruction!
  904.     move.l    a0,(2,sp)
  905.     bsr.b    _flush020
  906.     nop
  907.     rte
  908.  
  909. _flush020    move.l    d0,-(sp)
  910.     movec    cacr,d0
  911.     or.w    #CACRF_ClearI!CACRF_ClearD,d0
  912.     movec    d0,cacr
  913.     move.l    (sp)+,d0
  914.     rts
  915.  
  916.  
  917. ; runnommu -- run routine with mmu disabled
  918. ;
  919. ;  IN: a0=code to run in supervisor, mmu off. *MUST* return with rts!!
  920. ; OUT: d0=whatever values routine leaves to d0. cc's set accordingly.
  921. ;NOTE: only register guaranteed to be valid on return is d0
  922. runnommu    movem.l    a5/a6,-(sp)
  923.     move.l    (_mmubase,pc),-(sp)
  924.     bne    .use_mmulib
  925.     addq.l    #4,sp
  926.  
  927.     move.l    (_ExecBase,pc),a6
  928.     lea    (.discode,pc),a5
  929.     call    Disable
  930.     call    Supervisor
  931.     call    Enable
  932. .exit    movem.l    (sp)+,a5/a6
  933.     tst.l    d0
  934.     rts
  935. .discode    move.l    d0,-(sp)
  936.     subq.l    #4,sp
  937.     move.b    (_mmuflag,pc),d0
  938.     beq.b    .nommua
  939.     bmi.b    .is040a
  940.     dc.w    $F017,$4200        pmove.l tc,(sp)
  941.     clr.l    -(sp)
  942.     dc.w    $F017,$4000        pmove.l    (sp),tc
  943.     addq.l    #4,sp
  944.     bsr    _flush020
  945.     bra.b    .was030a
  946. .is040a    bsr.b    _fullflush040
  947.     movec    tc,d0
  948.     move.l    d0,(sp)
  949.     and.w    #$7F27,d0        E=%0, DCO=%00 DCI=%00
  950.     movec    d0,tc
  951.     bsr.b    _fullflush040
  952. .was030a    move.l    (4,sp),d0
  953. .nommua    nop
  954.     jsr    (a0)
  955.     move.l    d0,(4,sp)
  956.     move.b    (_mmuflag,pc),d0
  957.     beq.b    .nommub
  958.     bmi.b    .is040b
  959.     dc.w    $F017,$4000        pmove.l    (sp),tc
  960.     bsr    _flush020
  961.     bra.b    .nommub
  962. .is040b    bsr.b    _fullflush040
  963.     move.l    (sp),d0
  964.     movec    d0,tc
  965.     bsr.b    _fullflush040
  966. .nommub    addq.l    #4,sp
  967.     move.l    (sp)+,d0
  968.     nop
  969.     rte
  970.  
  971. .use_mmulib    move.l    (sp)+,a6
  972.     move.l    a0,a5
  973.     call    WithoutMMU
  974.     bra.b    .exit
  975.  
  976.  
  977. _fullflush040    FULLFLUSH040
  978.     rts
  979.  
  980.  
  981. TestBliz    movem.l    d1-a6,-(sp)
  982.     moveq    #0,d7            "No Blizzard board with maprom"
  983.     move.l    (_ExecBase,pc),a6
  984.  
  985.     bsr    .testblizppc
  986.     bne    .exit_np
  987.  
  988.     lea    (.ExpName,pc),a1
  989.     moveq    #33,d0
  990.     bsr    OpenLib
  991.     beq    .exit_np
  992.     move.l    d0,a6
  993.  
  994.     lea    (.boards,pc),a2
  995.     moveq    #0,d2
  996.     moveq    #0,d6            clear maprom address lower...
  997. .bfloop    moveq    #0,d0
  998.     moveq    #0,d1
  999.     move.w    (a2)+,d0        manufacturer
  1000.     bmi.b    .bfnomatch
  1001.     move.w    (a2)+,d1        product
  1002.     move.w    (a2)+,d6        maprom address, upper word
  1003.     move.l    (a2)+,d3        lower <<16 | upper ram area or -1
  1004.     sub.l    a0,a0
  1005.     call    FindConfigDev
  1006.     move.l    d0,d2
  1007.     beq.b    .bfloop
  1008. .bfnomatch    move.l    a6,a1
  1009.     move.l    (_ExecBase,pc),a6
  1010.     call    CloseLibrary
  1011.     tst.l    d2
  1012.     beq.b    .exit_np
  1013.     swap    d6            maprom address in d6
  1014.     move.l    d2,a0
  1015.     moveq    #0,d0
  1016.     move.b    (cd_Rom+er_Product,a0),d0
  1017.  
  1018.     lea    (_MK2,pc),a0
  1019.     cmp.w    #$19,d0
  1020.     seq    (a0)
  1021.     lea    (_B20x0,pc),a0
  1022.     cmp.w    #$18,d0
  1023.     seq    (a0)
  1024.     lea    (_CSPPC_MK3,pc),a0
  1025.     cmp.w    #$64,d0
  1026.     seq    (a0)
  1027.  
  1028.     move.l    d3,d0            lower & upper ram area for .csfindmemscan
  1029.     lea    (.blizfindmem,pc),a0
  1030.     addq.l    #1,d0
  1031.     beq.b    .skip            -1 it's blizzard!
  1032.     lea    (.csfindmem,pc),a0
  1033. .skip    call    Forbid
  1034.     lea    (MemList,a6),a5
  1035.     lea    (LH_TAIL,a5),a4
  1036.     jmp    (a0)
  1037.  
  1038. .exitsp
  1039.     move.l    d7,d0
  1040. .exit_known    call    Permit
  1041. .exit_np    tst.l    d0
  1042.     bne.b    .foundvalid
  1043.     lea    (_MemHeaderFlag,pc),a0
  1044.     clr.b    (a0)
  1045. .foundvalid    movem.l    (sp)+,d1-a6
  1046.     rts
  1047.  
  1048.  
  1049.  
  1050. .testblizppc    btst    #AFB_68040,(_AttnFlags+1,pc)
  1051.     beq    .pexit2
  1052.  
  1053.     lea    (.pidtag,pc),a1
  1054.     call    FindResident
  1055.     tst.l    d0
  1056.     bne.b    .foundit
  1057.  
  1058.     lea    (.nastyfind,pc),a0
  1059.     bsr    runnommu
  1060.     beq    .pexit2
  1061.  
  1062. .foundit    call    Forbid
  1063.  
  1064.     lea    (MemList,a6),a5
  1065.     lea    (LH_TAIL,a5),a4
  1066. .pscanloop    move.l    (a5),a5
  1067.     cmp.l    a5,a4
  1068.     beq    .pexit
  1069.     move.w    (MH_ATTRIBUTES,a5),d0
  1070.     and.w    #MEMF_POOLMEM!MEMF_PUBLIC!MEMF_CHIP!MEMF_FAST!MEMF_LOCAL!MEMF_24BITDMA,d0
  1071.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  1072.     bne.b    .pscanloop
  1073.     tst.l    (LN_NAME,a5)
  1074.     bne.b    .pscanloop
  1075.     cmp.l    #$40000000,(MH_LOWER,a5)
  1076.     blo.b    .pscanloop
  1077.     move.l    (MH_UPPER,a5),d0
  1078.     cmp.l    #$80000000,d0
  1079.     bhs.b    .pscanloop
  1080.     and.l    #$0007FFFF,d0
  1081.     beq.b    .pfoundit
  1082.  
  1083. .pexit    call    Permit
  1084. .pexit2    moveq    #0,d0
  1085.     rts
  1086.  
  1087. .pfoundit    bsr.b    .foundmem
  1088.  
  1089.     call    Permit
  1090.  
  1091.     lea    (_BlizPPC,pc),a0
  1092.     st    (a0)
  1093.  
  1094.     move.l    #$FFF00000,d0
  1095.     rts
  1096.  
  1097.  
  1098. .nastyfind    lea    $F00020,a0        BlizzPPC flash is located here...
  1099.     move.l    #4000,d0        Must use .l!
  1100.     movem.l    (.pidtag,pc),d1-d4
  1101.  
  1102. .nf_find    cmp.l    (a0),d1
  1103.     bne.b    .nf_more
  1104.     cmp.l    (4,a0),d2
  1105.     bne.b    .nf_more
  1106.     cmp.l    (8,a0),d3
  1107.     bne.b    .nf_more
  1108.     cmp.l    (12,a0),d4
  1109.     bne.b    .nf_more
  1110.  
  1111.     moveq    #1,d0
  1112.     rts
  1113.  
  1114. .nf_more    addq.l    #1,a0
  1115.     subq.l    #1,d0
  1116.     bne.b    .nf_find
  1117.     rts
  1118.  
  1119. .pidtag    dc.b    'BlizzardPPC.IDTag',0
  1120.     CNOP    0,2
  1121.  
  1122.  
  1123. .foundmem    move.l    a5,a0            for Allocate_REVERSE
  1124.     lea    (_memhead,pc),a1
  1125.     moveq    #MH_FIRST,d0
  1126.     call    CopyMem
  1127.     lea    (_MemHeaderFlag,pc),a0
  1128.     st    (a0)
  1129.     rts
  1130.  
  1131.  
  1132. .blizfindmem
  1133. .trymore    sub.l    a3,a3
  1134. .scanloop    move.l    (a5),a5
  1135.     cmp.l    a5,a4
  1136.     beq    .exitsp
  1137.     move.w    (MH_ATTRIBUTES,a5),d0
  1138.     and.w    #MEMF_POOLMEM!MEMF_CHIP!MEMF_FAST!MEMF_PUBLIC,d0    Public fast?
  1139.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  1140.     bne.b    .scanloop
  1141.     cmp.l    #$01000000,(MH_LOWER,a5)    32bit?
  1142.     blo.b    .scanloop
  1143.     move.l    (LN_NAME,a5),d0
  1144.     beq.b    .found
  1145.     move.l    d0,a2
  1146.     move.l    (a2),d0
  1147.     or.l    #$20202020,d0        To lowercase
  1148.     cmp.l    #'bliz',d0
  1149.     beq.b    .found
  1150.     tst.b    (a2)            null name -> buggy AllocMem result test!
  1151.     bne.b    .scanloop
  1152. .found
  1153.     bsr.b    .foundmem
  1154.  
  1155.     move.l    (MH_UPPER,a5),a3
  1156.  
  1157.     move.l    a3,d0            Test for MapROM:
  1158.     beq.b    .exit
  1159.     and.l    #$0007FFFF,d0
  1160.     bne.b    .exit
  1161.     move.l    a3,d0
  1162.     and.l    #$00080000,d0
  1163.     beq.b    .exit
  1164.  
  1165.     move.l    d6,d0            "known"?
  1166.     bne    .exit_known
  1167.  
  1168.     move.l    a3,a2
  1169.     add.l    #$80000-4,a2
  1170.     lea    $00F80000+$80000-4,a1
  1171.     lea    (_regtemp,pc),a0
  1172.     movem.l    a1/a2,(a0)
  1173.  
  1174.     lea    (.testcode,pc),a0
  1175.     bsr    runnommu
  1176.     beq.b    .exit
  1177.     move.l    a3,d7
  1178. .exit    tst.l    d7
  1179.     beq    .trymore
  1180.     bra    .exitsp
  1181.  
  1182.  
  1183. .is_mk2    move.l    #$08000000,d1
  1184.     move.l    #$10000000,d2
  1185. .mk2scanloop    move.l    (a5),a5
  1186.     cmp.l    a5,a4
  1187.     beq    .exitsp
  1188.     move.w    (MH_ATTRIBUTES,a5),d0
  1189.     and.w    #MEMF_POOLMEM!MEMF_CHIP!MEMF_FAST!MEMF_PUBLIC,d0    Public fast?
  1190.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  1191.     bne.b    .mk2scanloop
  1192.     cmp.l    (MH_LOWER,a5),d1
  1193.     bhi.b    .mk2scanloop        bug: was blo!
  1194.     cmp.l    (MH_UPPER,a5),d2
  1195.     blo.b    .mk2scanloop
  1196.  
  1197.     bsr    .foundmem
  1198.  
  1199.     move.l    (MH_UPPER,a5),d0
  1200.     move.l    #$80000,d1
  1201.     move.l    d0,d2
  1202.     and.l    d1,d2
  1203.     bne.b    .mk2skip
  1204.     sub.l    d1,d0
  1205. .mk2skip    move.l    d0,d7
  1206.     bra    .exitsp
  1207.  
  1208.  
  1209.  
  1210. .csfindmem    move.b    (_MK2,pc),d0
  1211.     bne.b    .is_mk2
  1212.  
  1213. .cstrymore    sub.l    a3,a3
  1214. .csscanloop    move.l    (a5),a5
  1215.     cmp.l    a5,a4
  1216.     beq    .exitsp
  1217.     move.w    (MH_ATTRIBUTES,a5),d0
  1218.     and.w    #MEMF_POOLMEM!MEMF_CHIP!MEMF_FAST!MEMF_PUBLIC,d0    Public fast?
  1219.     cmp.w    #MEMF_FAST!MEMF_PUBLIC,d0
  1220.     bne.b    .csscanloop
  1221.     swap    d3            ; get lower limit
  1222.     cmp.w    (MH_LOWER,a5),d3
  1223.     bhi.b    .csscanloop
  1224.     swap    d3            ; get upper limit
  1225.     cmp.w    (MH_UPPER,a5),d3
  1226.     blo.b    .csscanloop
  1227.  
  1228.     bsr    .foundmem
  1229.  
  1230.     move.l    (MH_UPPER,a5),a3
  1231.  
  1232.     move.l    a3,d0            Test for MapROM:
  1233.     beq.b    .csexit
  1234.     and.l    #$0007FFFF,d0
  1235.     bne.b    .csexit
  1236.  
  1237.     move.l    d6,d0            "known"?
  1238.     bne    .exit_known
  1239.  
  1240.     move.b    (_B20x0,pc),d0
  1241.     beq.b    .no20x0a
  1242.  
  1243.     cmp.w    #$0800,(MH_LOWER,a5)    Test for $08000000 mem.
  1244.     bne.b    .csexit
  1245.     move.l    a3,a2
  1246.     lea    (_regtemp,pc),a0
  1247.     move.l    a2,(a0)
  1248.     lea    (.testcode20x0,pc),a0
  1249.     bsr    runnommu
  1250.     beq.b    .csexit
  1251. .no20x0a
  1252.     move.l    a3,d7
  1253.  
  1254. .csexit    tst.l    d7
  1255.     beq    .cstrymore
  1256.     bra    .exitsp
  1257.  
  1258.  
  1259. ; a1=ROM, a2=RAM
  1260. .testcode    or.w    #$700,sr        Disable interrupts
  1261.     movem.l    (_regtemp,pc),a1/a2
  1262.  
  1263.     move.l    (a2),d1
  1264.     cmp.l    (a1),d1
  1265.     bne.b    .exite
  1266.     not.l    d1
  1267.     move.l    d1,(a2)
  1268.     bsr.b    .cacheclr
  1269.     cmp.l    (a1),d1
  1270.     sne    d0
  1271.     not.l    d1            Restore before testing!
  1272.     move.l    d1,(a2)            (this was bugged)
  1273.     bsr.b    .cacheclr
  1274.     tst.b    d0
  1275.     bne.b    .exite
  1276.     cmp.l    (a1),d1
  1277.     bne.b    .exite
  1278.     moveq    #1,d0
  1279.     rts
  1280. .exite    moveq    #0,d0
  1281.     rts
  1282.  
  1283. .cacheclr    btst    #AFB_68020,(_AttnFlags+1,pc)
  1284.     bne    CacheClrS
  1285.     rts
  1286.  
  1287.  
  1288. ; a2=RAM
  1289. .testcode20x0    or.w    #$700,sr        Disable interrupts
  1290.     move.l    (_regtemp,pc),a2
  1291.  
  1292.     moveq    #0,d4
  1293.  
  1294.     movec    dfc,d0
  1295.     move.l    d0,-(sp)
  1296.     moveq    #3,d0            Entry FC for Control Registers (also num of areas-1)
  1297.     movec    d0,dfc
  1298.     bsr.b    .cacheclr
  1299. .tcloop    moveq    #0,d1
  1300.     bsr    SetMemShadow
  1301.  
  1302.     bsr.b    .cacheclr
  1303.     nop
  1304.     move.l    (a2),d2
  1305.     move.l    d2,-(sp)
  1306.     eor.l    #$BADC0DE5,d2
  1307.     move.l    d2,(a2)
  1308.     nop
  1309.     bsr.b    .cacheclr
  1310.     move.l    (a2),d3
  1311.     move.l    (sp)+,(a2)
  1312.     nop
  1313.     bsr.b    .cacheclr
  1314.     cmp.l    d2,d3
  1315.     beq.b    .tcfound
  1316.     moveq    #1,d1
  1317.     bsr    SetMemShadow
  1318.     subq.l    #1,d0
  1319.     bpl.b    .tcloop
  1320.  
  1321. .tcexit    move.l    (sp)+,d0
  1322.     movec    d0,dfc
  1323.     bsr.b    .cacheclr
  1324.     move.l    d4,d0
  1325.     rts
  1326.  
  1327. .tcfound    lea    (_B20x0Bank,pc),a0    Self Modifying Code! MUST
  1328.     move.b    d0,(a0)            clear caches (.cacheclr does it)
  1329.     moveq    #1,d1
  1330.     bsr.b    SetMemShadow        Uses d0!
  1331.     moveq    #1,d4
  1332.     bra.b    .tcexit
  1333.  
  1334.  
  1335.  
  1336. BITEM    MACRO
  1337.     dc.w    \2,\3,\1
  1338.     dc.l    \4
  1339.     ENDM
  1340.  
  1341. .boards    BITEM $0000,BLIZPROD,$18,$08001000    18 2040-ERC/2060
  1342.     ;BITEM $0000,BLIZPROD,$0C,$08002000    0C Cyberstorm MKI
  1343.     BITEM $0000,BLIZPROD,$19,0        19 Cyberstorm MKII
  1344.     BITEM $FFF0,BLIZPROD,$64,$08002000    64 Cyberstorm MKIII / PPC
  1345.     BITEM $4FF8,BLIZPROD,$11,-1        11 1230-IV / 1260 / 1240-T/ERC
  1346.     BITEM $1EF8,BLIZPROD,$0D,-1        0D 1230-III
  1347.     BITEM $0FF8,BLIZPROD,$0B,-1        0B 1230-II
  1348. ;;    BITEM $????,BLIZPROD,$??,-1        0? 1230-I
  1349.     dc.w    -1
  1350.  
  1351.  
  1352. .ExpName    dc.b    'expansion.library',0
  1353.     CNOP    0,2
  1354.  
  1355.  
  1356. ;
  1357. ; This one is from old CyberMap I think...
  1358. ; Modified a bit.
  1359. ;
  1360. ;*********************************************************
  1361. ;*       writes memshadowregister of the given rambank
  1362. ;*       setmemshadow(D0=bank,D1=on/off (bool))
  1363. ;*********************************************************
  1364. ;*       $ 8    2    c
  1365. ;*       %100x yy10 1100 ---- ---- ---- ---- ----Shadow Register Format
  1366. ;*                    x = Set/Clr Flag  0=on 1=off
  1367. ;*                    y = Bank Number
  1368. MEMSHWREG    EQU    $82C00000        Shadow Enable Control Register
  1369. SetMemShadowN    moveq    #0,d0            Self Modifying Code!! Must clear
  1370. _B20x0Bank    EQU    *-1            caches before calling SetMemShadowN!
  1371. ; IN: d0=bank, d1=mode
  1372. SetMemShadow    movem.l    d0-d1/a0,-(sp)
  1373.     and.l    #3,d0            mask bank number
  1374.     ror.l    #6,d0            shift in place
  1375.     or.l    #MEMSHWREG,d0        mask in MEMSHWREG adr
  1376.     tst.l    d1
  1377.     bne.b    .sf_skip        =! 0 -> TRUE -> b28=0
  1378.     bset    #28,d0            == 0 -> FALSE -> b28=1
  1379. .sf_skip    move.l    d0,a0            Write Register
  1380.     moves.l    a0,(a0)
  1381.     movem.l    (sp)+,d0-d1/a0
  1382. ;;    rts
  1383.     bra    _fullflush040
  1384.  
  1385.  
  1386.  
  1387. ; FindMemHeader - find memheader even if it has moved by PoolMem
  1388. ; MUST call this in Forbid()! Use returned memheader before Permit()!
  1389. ;
  1390. ;  IN: a0=clone of MH (up to MH_FIRST) to find
  1391. ;      a6=execbase
  1392. ; OUT: a0=memheader or NULL, Z flag set
  1393. ;
  1394. FindMemHeader    movem.l    d0-d3/a1,-(sp)
  1395.     moveq    #0,d0
  1396.  
  1397.     move.w    (MH_ATTRIBUTES,a0),d1
  1398.     move.w    (LN_TYPE,a0),d2
  1399.     move.l    (LN_NAME,a0),d3
  1400.  
  1401.     lea    (MemList,a6),a0
  1402.     lea    (LH_TAIL,a0),a1
  1403. .find    move.l    (a0),a0
  1404.     cmp.l    a0,a1
  1405.     beq.b    .fail
  1406.     cmp.w    (MH_ATTRIBUTES,a0),d1
  1407.     bne.b    .find
  1408.     cmp.w    (LN_TYPE,a0),d2        type & pri
  1409.     bne.b    .find
  1410.     cmp.l    (LN_NAME,a0),d3
  1411.     bne.b    .find
  1412.  
  1413. .exit    move.l    a0,d0
  1414.     movem.l    (sp)+,d0-d3/a1
  1415.     rts
  1416.  
  1417. .fail    sub.l    a0,a0
  1418.     bra.b    .exit
  1419.  
  1420.  
  1421.  
  1422. ;  IN: a0=rom, d0=rom len
  1423. ; OUT: d0=success, fail if no AGA or WaitBlit func couln't be found
  1424. PutHogWaitBlit    movem.l    d1-a6,-(sp)
  1425.     moveq    #0,d7
  1426.  
  1427.     cmp.w    #39,($C,a0)        Requires rom 39+
  1428.     blo.b    .exit
  1429.  
  1430.     lea    -4(a0,d0.l),a1
  1431.  
  1432.     move.w    $DFF004,d0        Test AGA:
  1433.     and.w    #$7F00,d0
  1434.     lsr.w    #8,d0
  1435.     bclr    #4,d0
  1436.     cmp.b    #$22,d0
  1437.     beq.b    .aga
  1438.     cmp.b    #$23,d0
  1439.     bne.b    .exit
  1440. .aga
  1441.     move.l    #$08390006,d0
  1442. .find    addq.l    #2,a0
  1443.     cmp.l    a1,a0
  1444.     beq.b    .exit
  1445.     cmp.l    (a0),d0
  1446.     bne.b    .find
  1447.     cmp.l    #$00DFF002,(4,a0)
  1448.     bne.b    .find
  1449.     cmp.l    #$66024E75,(8,a0)
  1450.     bne.b    .find
  1451.  
  1452.     cmp.l    #$08390006,(-8,a0)    No KS 1.x!
  1453.     beq.b    .exit
  1454.     cmp.l    #$4A3900DF,(-6,a0)    KS 2.x/3.x:
  1455.     bne.b    .exit
  1456.     subq.l    #6,a0
  1457.     lea    (.waitblit,pc),a1
  1458.     moveq    #(.waitblitend-.waitblit)/2,d0
  1459. .copy    move.w    (a1)+,(a0)+
  1460.     subq.l    #1,d0
  1461.     bne.b    .copy
  1462.     moveq    #1,d7
  1463.  
  1464. .exit    move.l    d7,d0
  1465.     movem.l    (sp)+,d1-a6
  1466.     rts
  1467.  
  1468.     ; 1.x  36 bytes
  1469.     ; 2.05 40 bytes
  1470.     ; 3.0  48 bytes
  1471.     ; 3.1  48 bytes
  1472. .waitblit    btst    #DMAB_BLTDONE-8,$DFF000+dmaconr            8
  1473.     bne.b    .gowait                        2
  1474.     rts                            2
  1475. .gowait    move.l    a0,-(sp)                    2
  1476.     lea    ($DFF000+dmaconr),a0                6
  1477.     move.w    #DMAF_SETCLR!DMAF_BLITHOG,(dmacon-dmaconr,a0)    6
  1478. .wait    btst    #DMAB_BLTDONE-8,(a0)                4
  1479.     bne.b    .wait                        2
  1480.     move.w    #DMAF_BLITHOG,(dmacon-dmaconr,a0)        6
  1481.     move.l    (sp)+,a0                    2
  1482.     rts                            2 =42
  1483.     IFGT    0
  1484. .gowait    move.w    #DMAF_SETCLR!DMAF_BLITHOG,$DFF000+dmacon    8
  1485. .wait    btst    #DMAB_BLTDONE-8,$DFF000+dmaconr    8
  1486.     bne.b    .wait                2
  1487.     move.w    #DMAF_BLITHOG,$DFF000+dmacon    8
  1488.     rts                    2 =40
  1489.     ENDC
  1490. .waitblitend
  1491.     IFGT    (.waitblitend-.waitblit)-42
  1492.     FAIL    !! WAITBLIT routine too long !!
  1493.     ENDC
  1494.  
  1495.  
  1496.  
  1497. ;  IN: a0=rom start (buf)
  1498. ;      d0=rom len
  1499. ;      a1=name
  1500. ; OUT: d0=ptr to resident (buf) or NULL
  1501. FindResident    movem.l    d1-a6,-(sp)
  1502.     move.l    a1,a3
  1503.  
  1504.     move.l    d0,d4
  1505.     move.l    a0,a4
  1506.  
  1507.     moveq    #1,d6
  1508.     lea    (_erh_arealen,pc),a0
  1509.     move.l    (a0)+,d0
  1510.     beq.b    .try_rom
  1511.  
  1512.     move.l    (a0),a0
  1513.     sub.l    a5,a5            Difference=0
  1514.  
  1515. .findres    moveq    #RT_SIZE-2,d1
  1516.     sub.l    d1,d0
  1517.     move.w    #RTC_MATCHWORD,d1
  1518. .find    subq.l    #2,d0
  1519.     bls.b    .try_rom
  1520.     cmp.w    (a0)+,d1
  1521.     bne.b    .find
  1522.     moveq    #2,d2
  1523.     add.l    (a0),d2            (RT_MATCHTAG-2,a0),d2
  1524.     add.l    a5,d2
  1525.     cmp.l    a0,d2
  1526.     bne.b    .find
  1527.     move.l    (RT_NAME-2,a0),a1
  1528.     add.l    a5,a1
  1529.     move.l    a3,a2
  1530. .compare    cmpm.b    (a2)+,(a1)+
  1531.     bne.b    .find
  1532.     tst.b    (-1,a2)
  1533.     bne.b    .compare
  1534.  
  1535.     move.l    a0,d0
  1536.     subq.l    #2,d0
  1537.  
  1538. .exit    movem.l    (sp)+,d1-a6
  1539.     rts
  1540.  
  1541. .exit_nf    moveq    #0,d0
  1542.     bra.b    .exit
  1543.  
  1544. .try_rom    tst.l    d6
  1545.     beq.b    .exit_nf
  1546.  
  1547.     move.l    d4,d0
  1548.     move.l    a4,a0
  1549.  
  1550.     move.l    #$01000000,d1
  1551.     sub.l    d0,d1            d2=rom start (rom)
  1552.     move.l    a0,a5
  1553.     sub.l    d1,a5            a5=difference
  1554.  
  1555.     moveq    #0,d6
  1556.     bra.b    .findres
  1557.  
  1558.  
  1559. PATHBUF_SIZE    EQU    256
  1560.  
  1561. ;  IN: a0=ptr to rom (buf), d0=rom len, a3=array  (d6=dosbase)
  1562. ; OUT: d0=success, will print doserror if failed
  1563. DoPlanting    movem.l    d1-a6,-(sp)
  1564.     lea    (-PATHBUF_SIZE,sp),sp
  1565.     move.l    sp,a5
  1566.     move.l    d6,a6
  1567.  
  1568.     move.l    d0,d1
  1569.     move.l    (ARG_MODULE,a3),d0
  1570.     beq    .exit            OK! ;-)
  1571.     move.l    d0,a2
  1572.  
  1573.     IFND    NEW_ENV_METHOD
  1574.     moveq    #0,d3
  1575.     ENDC
  1576.     moveq    #0,d4            null!
  1577.     cmp.w    #37,(LIB_VERSION,a6)
  1578.     blo    .not20
  1579.  
  1580.     IFD    NEW_ENV_METHOD
  1581.  
  1582.     movem.l    d1-d3/a0,-(sp)
  1583.     sub.l    a1,a1
  1584.     move.l    (_ExecBase,pc),a6
  1585.     call    FindTask
  1586.     move.l    d6,a6
  1587.     move.l    d0,a0
  1588.     lea    (pr_WindowPtr,a0),a0
  1589.     move.l    (a0),-(sp)
  1590.     move.l    a0,-(sp)
  1591.     moveq    #-1,d0
  1592.     move.l    d0,(a0)
  1593.  
  1594.     lea    (_VarName,pc),a0
  1595.     move.l    a0,d1
  1596.     move.l    a5,d2
  1597.     move.l    #PATHBUF_SIZE,d3    d4=0
  1598.     call    GetVar
  1599.     addq.l    #1,d0
  1600.     bne.b    .gotvar
  1601.     lea    (_VarEnvArcName,pc),a0
  1602.     move.l    a0,d1
  1603.     call    GetVar
  1604.     addq.l    #1,d0
  1605.     bne.b    .gotvar
  1606.  
  1607.     lea    (_VarEnvArcName,pc),a0
  1608.     move.l    a0,d1
  1609.     move.l    #MODE_OLDFILE,d2
  1610.     call    Open
  1611.     move.l    d0,d4            d4=0 if failed, no dirlock
  1612.     beq.b    .novar
  1613.     move.l    d4,d1
  1614.     move.l    a5,d2
  1615.     subq.l    #1,d3            #PATHBUF_SIZE-1
  1616.     call    Read
  1617.     move.l    d0,d2
  1618.     move.l    d4,d1
  1619.     call    Close
  1620.     tst.l    d2
  1621.     bmi.b    .novar
  1622.     clr.b    0(a5,d2.l)        null terminate
  1623.     move.l    a5,a0            strip linefeeds
  1624. .filt_loop    move.b    (a0)+,d0
  1625.     beq.b    .filt_end
  1626.     cmp.b    #10,d0
  1627.     bne.b    .filt_loop
  1628.     clr.b    -(a0)
  1629. .filt_end
  1630. .gotvar
  1631.     move.l    a5,d1
  1632.     bsr    _lockread
  1633.     beq.b    .nolock
  1634.     move.l    d1,d4
  1635.     call    CurrentDir
  1636.     move.l    d0,d7            oldlock
  1637. .nolock
  1638. .novar
  1639.     move.l    (sp)+,a0
  1640.     move.l    (sp)+,(a0)
  1641.  
  1642.     movem.l    (sp)+,d1-d3/a0
  1643. .not20
  1644.  
  1645.     ELSE
  1646.  
  1647.     movem.l    d1-d2/a0,-(sp)
  1648.     sub.l    a1,a1
  1649.     move.l    (_ExecBase,pc),a6
  1650.     call    FindTask
  1651.     move.l    d6,a6
  1652.     move.l    d0,a0
  1653.     lea    (pr_WindowPtr,a0),a0
  1654.     move.l    (a0),-(sp)
  1655.     move.l    a0,-(sp)
  1656.     moveq    #-1,d0
  1657.     move.l    d0,(a0)
  1658.  
  1659.     lea    (_EnvName,pc),a0
  1660.     move.b    #':',(3,a0)
  1661.     move.l    a0,d1
  1662.     bsr    _lockread
  1663.     move.l    d0,d2
  1664.     call    UnLock
  1665.     move.l    (sp)+,a0
  1666.     move.l    (sp)+,(a0)
  1667.     tst.l    d2
  1668.     bne.b    .has_env
  1669.  
  1670.     lea    (_EnvArcName,pc),a0
  1671.     move.l    a0,d1
  1672.     bsr    _lockread
  1673.     beq.b    .no_envarclock
  1674.     move.l    d0,d2
  1675.     lea    (_EnvName,pc),a0
  1676.     clr.b    (3,a0)
  1677.     move.l    a0,d1
  1678.     call    AssignLock
  1679.     move.l    d0,d3            d3=assignstate
  1680.     bne.b    .got_assign
  1681.     move.l    d2,d1
  1682.     call    UnLock
  1683. .got_assign
  1684. .no_envarclock
  1685. .has_env
  1686.     lea    (_VarName,pc),a0
  1687.     move.l    a0,d1
  1688.     move.l    a5,d2
  1689.     move.l    d3,-(sp)
  1690.     move.l    #PATHBUF_SIZE,d3    d4=0
  1691.     call    GetVar
  1692.     move.l    (sp)+,d3
  1693.     addq.l    #1,d0
  1694.     beq.b    .novar
  1695.     move.l    a5,d1
  1696.     bsr    _lockread
  1697.     beq.b    .nolock
  1698.     move.l    d0,d4
  1699.     move.l    d4,d1
  1700.     call    CurrentDir
  1701.     move.l    d0,d7            oldlock
  1702. .nolock
  1703. .novar    movem.l    (sp)+,d1-d2/a0
  1704. .not20
  1705.     ENDC
  1706.  
  1707. .loop    move.l    (a2)+,d0
  1708.     beq.b    .exit2
  1709.     move.l    d0,a1
  1710.     move.l    d1,d0
  1711.     bsr.b    FilePlant
  1712.     bne.b    .loop
  1713.     bsr    _PrintFault        IN: d5=kickflag, d6=dosbase
  1714.     lea    (PlantError,pc),a0
  1715.     move.l    a2,a1
  1716.     subq.l    #4,a1
  1717.     bsr    _Printf
  1718.     moveq    #-1,d0
  1719.  
  1720. .exit2    tst.l    d4
  1721.     beq.b    .nodirlock
  1722.     move.l    d0,-(sp)
  1723.     move.l    d7,d1
  1724.     call    CurrentDir
  1725.     move.l    d4,d1
  1726.     call    UnLock
  1727.     move.l    (sp)+,d0
  1728. .nodirlock
  1729.     IFND    NEW_ENV_METHOD
  1730.  
  1731.     tst.l    d3
  1732.     beq.b    .noassign
  1733.     move.l    d0,d7
  1734.     lea    (_EnvName,pc),a0
  1735.     clr.b    (3,a0)
  1736.     move.l    a0,d1
  1737.     moveq    #0,d2
  1738.     call    AssignLock
  1739.     move.l    d7,d0
  1740. .noassign
  1741.     ENDC
  1742.  
  1743. .exit    not.l    d0
  1744.     lea    (PATHBUF_SIZE,sp),sp
  1745.     movem.l    (sp)+,d1-a6
  1746.     rts
  1747.  
  1748. _lockread    moveq    #ACCESS_READ,d2
  1749.     call    Lock
  1750.     move.l    d0,d1
  1751.     rts
  1752.  
  1753. ;  IN: a1=ptr to filename, a0=ptr to rom (buf), d0=rom len  (d6=dosbase)
  1754. ; OUT: d0=success
  1755. FilePlant    movem.l    d1-a6,-(sp)
  1756.     move.l    d6,a6
  1757.     moveq    #0,d7
  1758.  
  1759.     lea    (.data,pc),a4
  1760.     movem.l    d0/a0,(a4)
  1761.  
  1762.     move.l    a1,d1
  1763.     call    LoadSeg
  1764.     move.l    d0,d5
  1765.     beq.b    .exit
  1766.  
  1767.     move.l    d5,a1
  1768.     add.l    a1,a1
  1769.     addq.l    #2,a1            ;-)
  1770.     add.l    a1,a1
  1771.     movem.l    (a4),d0/a0
  1772.     bsr    InstallModule
  1773.     move.l    d0,d7
  1774.     bne.b    .was_module
  1775.  
  1776.     ; try direct executable planting
  1777.  
  1778.     cmp.l    #BKMODULE_ID,(a1)    was it a module that failed?
  1779.     beq.b    .was_module        yes, quit!
  1780.  
  1781.     ; the test above is really needed or else horrors
  1782.     ; would happen. namely installing non-functional
  1783.     ; resident tag that would crash system.
  1784.  
  1785.     move.l    (8*4,sp),d1        filename from stack
  1786.     move.l    #MODE_OLDFILE,d2
  1787.     call    Open
  1788.     move.l    d0,d4
  1789.     beq.b    .exit
  1790.  
  1791.     lea    (.af_dosbase,pc),a0
  1792.     move.l    a6,(a0)
  1793.  
  1794.     pea    (.freefunc,pc)
  1795.     pea    (.allocfunc,pc)
  1796.     pea    (.readfunc,pc)
  1797.     move.l    sp,a1
  1798.     clr.l    -(sp)
  1799.     move.l    sp,a2
  1800.     sub.l    a0,a0
  1801.     ; d0=filehandle
  1802.     call    InternalLoadSeg
  1803.     lea    (4*4,sp),sp
  1804.     move.l    d0,d7
  1805.  
  1806.     move.l    d4,d1
  1807.     call    Close
  1808.     
  1809. .was_module    move.l    d5,d1
  1810.     beq.b    .exit
  1811.     call    UnLoadSeg
  1812. .exit    move.l    d7,d0
  1813.     movem.l    (sp)+,d1-a6
  1814.     rts
  1815.  
  1816.  
  1817.  
  1818. .data    ds.l    2
  1819.  
  1820. ;  IN: d0=size, d1=flags
  1821. ; OUT: d0=memory
  1822. .allocfunc    tst.l    d0
  1823.     bne.b    .af_do
  1824.  
  1825. .af_fail    move.l    a6,-(sp)
  1826.     move.l    (.af_dosbase,pc),a6
  1827.     moveq    #ERROR_NO_FREE_STORE,d1
  1828.     call    SetIoErr
  1829.     move.l    (sp)+,a6
  1830.     moveq    #0,d0
  1831.     rts
  1832.  
  1833. .af_do    btst    #MEMB_CHIP,d1        don't allow chipmem
  1834.     bne.b    .af_fail
  1835.  
  1836.     movem.l    d0/d1,-(sp)
  1837.     move.l    (_erh_memheader,pc),d0
  1838.     beq.b    .af_exit
  1839.     move.l    d0,a0
  1840.     move.l    (sp),d0
  1841.     call    Allocate
  1842.     tst.l    d0
  1843.     beq.b    .af_nomem
  1844.     ; d0=return val
  1845.  
  1846.     ; should clear allocated area?
  1847.     btst    #MEMB_CLEAR-16,(1,sp)
  1848.     beq.b    .af_exit
  1849.  
  1850.     ; get original alloc req and align it
  1851.     move.l    (sp),d1
  1852.     addq.l    #MEM_BLOCKMASK,d1
  1853.     and.w    #-MEM_BLOCKSIZE,d1
  1854.  
  1855.     move.l    d0,a0
  1856. .af_clear    clr.l    (a0)+
  1857.     clr.l    (a0)+
  1858.     subq.l    #8,d1
  1859.     bne.b    .af_clear
  1860.  
  1861. .af_exit    addq.l    #8,sp
  1862.     rts
  1863.  
  1864. .af_nomem    addq.l    #8,sp
  1865.     bra.b    .af_fail
  1866.  
  1867. .af_dosbase    ds.l    1
  1868.  
  1869.  
  1870. ;  IN: a1=memory d0=size
  1871. ; OUT: -
  1872. .freefunc    tst.l    d0
  1873.     bne.b    .ff_do
  1874. .ff_no    rts
  1875. .ff_do    move.l    a1,d1
  1876.     beq.b    .ff_no
  1877.  
  1878.     move.l    (_erh_memheader,pc),d1
  1879.     beq.b    .ff_no
  1880.  
  1881.     movem.l    d0/a1,-(sp)
  1882.     move.l    a1,d1
  1883.     and.w    #-MEM_BLOCKSIZE,d1
  1884.     exg    d1,a1
  1885.     addq.l    #MEM_BLOCKMASK,d0
  1886.     sub.l    a1,d1
  1887.     add.l    d1,d0
  1888.     moveq    #-1,d1
  1889.     and.l    #-MEM_BLOCKSIZE,d0    note: .l!!
  1890.     beq.b    .ff_nofill
  1891. .ff_fill    move.l    d1,(a1)+
  1892.     move.l    d1,(a1)+
  1893.     subq.l    #8,d0
  1894.     bne.b    .ff_fill
  1895. .ff_nofill    movem.l    (sp)+,d0/a1
  1896.  
  1897.     move.l    (_erh_memheader,pc),a0
  1898.     jmp    (_LVODeallocate,a6)
  1899.  
  1900. ;  IN: d1=fh, d2=buffer, d3=len
  1901. ; OUT: d0=actual
  1902. .readfunc    jmp    (_LVORead,a6)
  1903.  
  1904.  
  1905.  
  1906. ;  IN: d1.l=error (d6=dosbase)
  1907. SetIoErr    movem.l    d0-d1/a0-a1/a6,-(sp)
  1908.     move.l    d6,a6
  1909.     cmp.w    #36,(LIB_VERSION,a6)
  1910.     blo.b    .old
  1911.     call    SetIoErr
  1912.     bra.b    .exit
  1913. .old    move.l    (_ExecBase,pc),a6
  1914.     sub.l    a1,a1
  1915.     call    FindTask
  1916.     move.l    d0,a0
  1917.     move.l    (4,sp),(pr_Result2,a0)
  1918. .exit    movem.l    (sp)+,d0-d1/a0-a1/a6
  1919.     rts
  1920.  
  1921.  
  1922. ;  IN: a1=ptr to module, a0=ptr to rom (buf), d0=rom len  (d6=dosbase)
  1923. ; OUT: d0=success, d1/a0/a1 preserved
  1924. InstallModule    movem.l    d1-a6,-(sp)
  1925.     moveq    #0,d7
  1926.     move.l    #ERROR_OBJECT_WRONG_TYPE,d1
  1927.     bsr.b    SetIoErr
  1928.  
  1929.     move.l    #$01000000,d2
  1930.     sub.l    d0,d2
  1931.     move.l    a0,a5
  1932.     sub.l    d2,a5            a5=difference
  1933.  
  1934.     cmp.l    #BKMODULE_ID,(a1)+    (bkm_ID)
  1935.     bne.b    .exit
  1936.     move.w    (a1)+,d4        d4=bkm_Flags, a1=bkm_ResTag
  1937.     move.w    d4,d1
  1938.     and.w    #~BKMF_ALL,d1        Test validity:
  1939.     bne.b    .exit
  1940.     cmp.w    #BKEP_ID,(a1)        Test for patch module:
  1941.     beq    .is_epatch
  1942.     cmp.l    #RTC_MATCHWORD<<16,(a1)
  1943.     bne.b    .exit
  1944.  
  1945.     move.l    #ERROR_OBJECT_TOO_LARGE,d1
  1946.     bsr.b    SetIoErr
  1947.  
  1948.     lea    (.replace_test,pc),a3
  1949.     lsr.w    #1,d4            btst    #BKMB_ReplaceMode,d4
  1950.     bcs.b    .replace
  1951.     lea    (.single_test,pc),a3
  1952.     lsr.w    #1,d4            btst    #BKMB_SingleMode,d4
  1953.     bcc.b    .no_findresident
  1954. .replace    movem.l    d0/a1,-(sp)
  1955.     add.l    (RT_NAME,a1),a1
  1956.     bsr    FindResident
  1957.     move.l    d0,a2
  1958.     movem.l    (sp)+,d0/a1
  1959.     jmp    (a3)
  1960. .no_findresident
  1961. .is_single
  1962. .is_erbf    move.l    (RT_ENDSKIP,a1),d1
  1963.     lsr.w    #1,d4            btst    #BKMB_ExtResBuf,d4
  1964.     bcc.b    .no_extresbuf1
  1965.     neg.l    d1
  1966. .no_extresbuf1    bsr    FindSpace
  1967.     beq.b    .exit
  1968.  
  1969. .go_replace    move.l    d0,a3            a3=ptr to func (buf)
  1970.     move.l    d1,a2            a2=ptr to func (ROM)
  1971.  
  1972.     move.w    ($C,a0),d1        d1=rom version
  1973.     move.l    a1,a0
  1974.     lea    (RT_VERSION,a0),a4
  1975.     cmp.b    (a4),d1            Test version!
  1976.     blo.b    .nofail
  1977.     move.b    d1,(a4)            Force current version!
  1978.     cmp.w    #36,d1
  1979.     shs    d1
  1980.     move.l    a3,a1            a2=ptr to func (ROM)
  1981.     bsr    PutResident
  1982.  
  1983. .nofail    moveq    #1,d7
  1984. .exit    move.l    d7,d0
  1985. .exit2    bsr    CacheClearOS        Clear caches.
  1986.     movem.l    (sp)+,d1-a6
  1987.     rts
  1988.  
  1989.  
  1990. .replace_test    beq.b    .exit            If no match exit!
  1991.     move.b    (RT_PRI,a2),d1
  1992.     cmp.b    (RT_PRI,a1),d1
  1993.     bne.b    .exit            If no match exit!
  1994.  
  1995.     lsr.w    #1,d4
  1996.     btst    #0,d4            btst BKMB_ExtResBuf,d4
  1997.     bne.b    .is_erbf
  1998.  
  1999.     move.l    (RT_ENDSKIP,a2),d1    d1=ptr to ENDSKIP (ROM)
  2000.     add.l    a5,d1            d1=ptr to ENDSKIP (buf)
  2001.     sub.l    a2,d1
  2002.     cmp.l    (RT_ENDSKIP,a1),d1
  2003.     ble.b    .exit
  2004.     move.l    a2,d0
  2005.     move.l    d0,d1
  2006.     sub.l    a5,d1
  2007.     bra.b    .go_replace
  2008.  
  2009.  
  2010. .single_test    beq.b    .is_single        SINGLE: If no match continue!
  2011.     move.b    (RT_PRI,a2),d1
  2012.     cmp.b    (RT_PRI,a1),d1
  2013.     bne.b    .is_single        SINGLE: If no match continue!
  2014.     move.l    #ERROR_TOO_MANY_ARGS,d1
  2015.     bsr    SetIoErr
  2016.     move.l    d0,d7
  2017.     bra.b    .exit
  2018.  
  2019. ; a0=ptr to rom start (buf), a1=ptr to epatch, d0=rom len, d2=ptr to rom start (ROM)
  2020. .is_epatch    lea    (2,a1),a5
  2021.     move.l    d2,a1
  2022.     lea    (FindResident,pc),a2
  2023.     lea    (InstallModule,pc),a3
  2024.     lea    (_Printf,pc),a4
  2025.     move.l    (_ExecBase,pc),a6
  2026.     jsr    (a5)
  2027.     bra.b    .exit2
  2028.  
  2029.  
  2030. ;  IN: a0=rom (buf), d0=rom len, d1=required space (negate if ExtResBuf required)
  2031. ; OUT: d0=ptr to area (buf) or NULL, d1=ptr to area (rom)
  2032. ;NOTE: condition codes set on return!
  2033. FindSpace    movem.l    d2-d3/d6-d7/a0-a2,-(sp)
  2034.     moveq    #0,d7
  2035.  
  2036.     move.l    #$01000000,d2
  2037.     sub.l    d0,d2
  2038.     move.l    a0,d6
  2039.     sub.l    d2,d6            d6=difference (buf-rom)
  2040.  
  2041.     tst.l    d1
  2042.     bmi.b    .required_extres
  2043.  
  2044.     lea    ROMSUMOFFS(a0,d0.l),a1
  2045.     bsr.b    .find
  2046.     bhs.b    .found            Big enough 'empty' space.
  2047.  
  2048.     move.l    #$00040000,d2
  2049.     cmp.l    d2,d0            Test for >$40000 ROM
  2050.     bls.b    .try_extres
  2051.  
  2052.     lea    (a0,d0.l),a1
  2053.     sub.l    d2,a1            a1=$FC0000
  2054.     move.l    (a1),d2
  2055.     and.l    #$FFF8FFFF,d2
  2056.     cmp.l    #$11104EF9,d2
  2057.     bne.b    .try_extres
  2058.     bsr.b    .find
  2059.     blo.b    .try_extres
  2060.  
  2061. .found    move.l    a1,d7
  2062.     addq.l    #1+3,d7
  2063.     and.w    #-4,d7
  2064.  
  2065. .exit    move.l    d7,d1
  2066.     sub.l    d6,d1
  2067.     move.l    d7,d0
  2068.     movem.l    (sp)+,d2-d3/d6-d7/a0-a2
  2069.     rts
  2070.  
  2071. .find    moveq    #-1,d2
  2072. .null    move.b    -(a1),d3
  2073.     addq.l    #1,d2
  2074.     not.b    d3
  2075.     beq.b    .null
  2076.     cmp.l    d1,d2
  2077.     rts
  2078.  
  2079. .required_extres
  2080.     neg.l    d1
  2081. .try_extres    move.l    (_erh_memheader,pc),d0
  2082.     beq.b    .exit
  2083.     move.l    d0,a0
  2084.     move.l    d1,d0
  2085.     move.l    a6,-(sp)
  2086.     move.l    (_ExecBase,pc),a6
  2087.     call    Allocate
  2088.     move.l    (sp)+,a6
  2089.     move.l    d0,d7
  2090.     moveq    #0,d6            NULL difference!
  2091.     bra.b    .exit
  2092.  
  2093.  
  2094. ;  IN: a0=resident
  2095. ;      a1=adr to "free" buf
  2096. ;      a2=adr to "free" buf (rom)
  2097. ;      d1.b=zero if <V36 ROM
  2098. PutResident    ;bsr    CacheClearOS        336r: Added coz bad move16 optimized copymem patches?
  2099.     movem.l    d0-a6,-(sp)
  2100.     move.l    (_ExecBase,pc),a6
  2101.     lea    (RT_MATCHTAG,a1),a3
  2102.     lea    (4,a1),a4
  2103.     move.l    (RT_ENDSKIP,a0),d0
  2104.     call    CopyMem
  2105.     ;bsr    CacheClearOS        336r: Added coz bad move16 optimized copymem patches?
  2106.     move.l    a2,d0
  2107.     move.l    d0,(a3)+        RT_MATCHTAG
  2108.     add.l    d0,(a3)+        RT_ENDSKIP
  2109.     tst.b    (4+3,sp)        V36+ ?
  2110.     bne.b    .no_incomp
  2111.     move.b    (a3),d1
  2112.     and.b    #~(RTF_AUTOINIT!RTW_COLDSTART),d1
  2113.     beq.b    .no_incomp
  2114.     and.b    #RTF_AUTOINIT!RTW_COLDSTART,(a3) Mask out incompatible bits
  2115.     or.b    #RTW_COLDSTART,(a3)
  2116. .no_incomp    move.b    (a3),d1
  2117.     addq.l    #RT_NAME-RT_FLAGS,a3
  2118.     add.l    d0,(a3)+        RT_NAME
  2119.     add.l    d0,(a3)+        RT_IDSTRING
  2120.     and.b    #RTF_AUTOINIT,d1
  2121.     beq.b    .noauto
  2122.     add.l    (a3),a4
  2123.     add.l    d0,(a4)+
  2124.     add.l    d0,(a4)+
  2125.     add.l    d0,(a4)+
  2126. .noauto    add.l    d0,(a3)+        RT_INIT
  2127.     movem.l    (sp)+,d0-a6
  2128.     rts
  2129.  
  2130.  
  2131. ;  IN: a0=rom (buf), d0=rom len, d1=required buffer len, d2=sanity size
  2132. ;      a6=execbase, d6=dosbase
  2133. ; OUT: d0=ptr to extres buffer or NULL
  2134. ExtResBuf    movem.l    d0-a6,-(sp)
  2135.     moveq    #0,d7
  2136.  
  2137.     move.l    d0,d5            d5=rom len
  2138.     move.l    a0,a5            a0=buf strt
  2139.  
  2140.     move.l    #ERROR_OBJECT_WRONG_TYPE,d1
  2141.     bsr    SetIoErr
  2142.  
  2143.     cmp.w    #37,($C,a5)        need 37+
  2144.     blo    .exit
  2145.  
  2146.     move.b    (_MemHeaderFlag,pc),d0
  2147.     beq    .exit
  2148.  
  2149.     ; find exec.library resident tag
  2150.  
  2151.     move.l    a5,a0
  2152.     move.l    d5,d0
  2153.     lea    (.execname,pc),a1
  2154.     bsr    FindResident
  2155.     tst.l    d0
  2156.     beq    .exit
  2157.  
  2158.     move.l    d0,a3
  2159.     move.l    (RT_INIT,a3),d1
  2160.  
  2161.     ;test if inside rom bounds?
  2162.     cmp.l    #$0f80000,d1
  2163.     blo    .exit
  2164.     cmp.l    #$1000000,d1
  2165.     bhs    .exit
  2166.  
  2167.     ; generate ram buffer address
  2168.     sub.l    #$f80000,d1        -$f80000
  2169.     add.l    a5,d1            +buffer
  2170.     move.l    d1,a0
  2171.  
  2172.     moveq    #12,d4            skip 12 bytes
  2173.     cmp.l    #$41F900DF,(a0)        37.x
  2174.     beq.b    .use12
  2175.     moveq    #4,d4            skip 4 bytes
  2176.     cmp.w    #$41FA,(a0)        39.x/40.x
  2177.     bne    .exit
  2178. .use12    add.l    (RT_INIT,a3),d4
  2179.  
  2180.     move.l    #extreshandler_SIZEOF+ERHANDLER_SIZEOF+8+MH_SIZE+7,d0
  2181.     add.l    (1*4,sp),d0        d1 from stack
  2182.     and.w    #-8,d0            align by 8
  2183.  
  2184.     ; use this to set up MH_UPPER, MH_FREE,
  2185.     ; MC_BYTES, ScanEnd...
  2186.     move.l    d0,d2
  2187.     sub.l    #extreshandler_SIZEOF,d2
  2188.  
  2189.     ; len for allocabs
  2190.     move.l    d0,d3
  2191.  
  2192.     ; add sanity just in case (something in boot could alloc
  2193.     ; MEMF_REVERSE overwriting us...)
  2194.     ;
  2195.     ; If user sees 80010000 alert he/she should increase
  2196.     ; SANITY
  2197.  
  2198.     add.l    #$90000,d0        add 576k... (internal sanity)
  2199.     add.l    (2*4,sp),d0        d2 from stack
  2200.  
  2201.     lea    (_erh_alloclen,pc),a0
  2202.     move.l    d0,(a0)
  2203.  
  2204.     call    Forbid
  2205.     lea    (_memhead,pc),a0
  2206.     bsr    FindMemHeader
  2207.     beq    .cantfind
  2208.     bsr    Allocate_REVERSE
  2209.     ;call    Allocate
  2210.     call    Permit
  2211.     lea    (_erh_freeaddr,pc),a0
  2212.     move.l    d0,(a0)
  2213.     beq    .exit
  2214.  
  2215.     move.l    d0,a2
  2216.     move.l    d0,a1
  2217.     addq.l    #8,a2            jump over two longs
  2218.  
  2219.     lea    (extreshandler,pc),a0
  2220.     moveq    #extreshandler_SIZEOF,d0
  2221.     call    CopyMem
  2222.  
  2223.     lea    (extreshandler_SIZEOF-8,a2),a0
  2224.     move.l    a0,d0
  2225.  
  2226.     lea    (_erh_memheader,pc),a1
  2227.     move.l    a0,(a1)
  2228.     lea    (MH_SIZE,a0),a1
  2229.     clr.l    (a0)+            LN_SUCC
  2230.     clr.l    (a0)+            LN_PRED
  2231.     move.w    #NT_MEMORY<<8,(a0)+    LN_TYPE, LN_PRI
  2232.     clr.l    (a0)+            LN_NAME
  2233.     clr.w    (a0)+            MH_ATTRIBUTES
  2234.     move.l    a1,(a0)+        MH_FIRST
  2235.     move.l    a1,(a0)+        MH_LOWER
  2236.     add.l    d2,d0            d0 = a1 - (MH_SIZE+8) + size
  2237.     move.l    d0,(a0)+        MH_UPPER
  2238.     moveq    #-(MH_SIZE+8),d0
  2239.     add.l    d2,d0
  2240.     move.l    d0,(a0)+        MH_FREE
  2241.     move.l    a0,d7
  2242.     clr.l    (a0)+            MC_NEXT
  2243.     move.l    d0,(a0)+        MC_BYTES
  2244.  
  2245.     subq.l    #8,d0
  2246.     moveq    #-1,d1
  2247. .fill    move.l    d1,(a0)+
  2248.     move.l    d1,(a0)+
  2249.     subq.l    #8,d0
  2250.     bne.b    .fill
  2251.  
  2252.  
  2253.     move.l    a2,d0
  2254.     lea    (allocpt+2,pc),a0
  2255.     subq.l    #8,d0
  2256.     move.l    d0,(a0)
  2257.     lea    (alloclen+2,pc),a0
  2258.     move.l    d3,(a0)
  2259.  
  2260.     move.l    d7,(scanstartoffs-8,a2)
  2261.     lea    (_erh_areastart,pc),a0
  2262.     move.l    d7,(a0)
  2263.     moveq    #-(MH_SIZE+8),d0
  2264.     add.l    d2,d0
  2265.     lea    (_erh_arealen,pc),a0
  2266.     move.l    d0,(a0)
  2267.     add.l    d7,d0
  2268.     move.l    d0,(scanendoffs-8,a2)
  2269.     move.l    d4,(jumpoffs-8,a2)
  2270.     move.l    a2,(RT_INIT,a3)
  2271.  
  2272.  
  2273.     move.l    a5,a0            a0=ptr to rom (buf)
  2274.     move.l    d5,d0            d0=rom len
  2275.     lea    (_erhandler_module,pc),a1
  2276.     bsr    InstallModule
  2277.     tst.l    d0
  2278.     bne.b    .exit
  2279.  
  2280.     bsr    FreeExtResBuf
  2281.     moveq    #0,d7
  2282.  
  2283.  
  2284. .exit    move.l    d7,d0
  2285.     addq.l    #4,sp
  2286.     movem.l    (sp)+,d1-a6
  2287.     rts
  2288.  
  2289. .cantfind    call    Permit
  2290.     bra.b    .exit
  2291.  
  2292.  
  2293. .execname    dc.b    'exec.library',0
  2294.     CNOP    0,2
  2295.  
  2296.     ; IN: a6=execbase
  2297. extreshandler    dc.l    0,0            don't trust 8 bytes we AllocAbs
  2298.  
  2299.     lea    (.areas,pc),a0
  2300.     dc.w    $4ef9
  2301. jumpoffs    EQU    *-extreshandler
  2302.     dc.l    $badc0de
  2303.  
  2304.  
  2305. .areas    dc.l    $0F80000
  2306.     dc.l    $1000000
  2307.     dc.l    $0F00000
  2308.     dc.l    $0F80000
  2309. scanstartoffs    EQU    *-extreshandler
  2310.     dc.l    $15c0ded
  2311. scanendoffs    EQU    *-extreshandler
  2312.     dc.l    $badd1e
  2313.     dc.l    -1
  2314.  
  2315. extreshandler_SIZEOF    EQU    (*-extreshandler+7)&-8
  2316.  
  2317.  
  2318.  
  2319.  
  2320. ;  IN: a0=memHeader, d0=byteSize, a6=execbase
  2321. ; OUT: d0=memoryBlock or null
  2322. Allocate_REVERSE
  2323.     sub.l    a1,a1            ; default
  2324.     jsr    (_LVOForbid,a6)
  2325.     move.l    (MH_FIRST,a0),d1
  2326.     beq.b    .fail
  2327.  
  2328.     ; find last MH that matches out requirements
  2329. .findfree_r    move.l    d1,a0
  2330.     cmp.l    (MC_BYTES,a0),d0
  2331.     bhi.b    .findskip_r
  2332.     move.l    a0,a1
  2333. .findskip_r    move.l    (a0),d1            ; MC_NEXT
  2334.     bne.b    .findfree_r
  2335.  
  2336.     ; found any?
  2337.     move.l    a1,d1
  2338.     beq.b    .fail
  2339.  
  2340.     ; allocate from it!
  2341.     move.l    (MC_BYTES,a1),d1
  2342.     sub.l    d0,d1
  2343.     and.w    #-8,d1
  2344.     add.l    d1,a1
  2345.     jsr    (_LVOAllocAbs,a6)
  2346.     jsr    (_LVOPermit,a6)
  2347.     tst.l    d0
  2348.     rts
  2349.  
  2350. .fail    jsr    (_LVOPermit,a6)
  2351.     moveq    #0,d0
  2352.     rts
  2353.  
  2354.  
  2355.  
  2356.     STRUCTURE BKERHSS,0
  2357.     STRUCT    BKERHSS_ss,SS_SIZE
  2358.     ULONG    BKERHSS_version
  2359.     UWORD    BKERHSS_unused0
  2360.     APTR    BKERHSS_memheader
  2361.     LABEL    BKERHSS_SIZEOF
  2362.  
  2363. _erhandler_module
  2364.  BK_MOD BKMF_SingleMode|BKMF_ExtResBuf,_erhandler_end,(RTF_COLDSTART)<<24!37<<16!NT_UNKNOWN<<8!104,_erh_name,_erh_name,_ERHandler
  2365. ;
  2366. ; IMPORTANT:
  2367. ; priority is after `diag init' resident that adds memory to system
  2368. ;
  2369.  
  2370.     ; d0=0, a0=0, a6=execbase
  2371. _ERHandler    ; reallocate EXTRESBUF
  2372. allocpt    lea    $deadc0de,a1
  2373. alloclen    move.l    #$cafecafe,d0
  2374.     call    AllocAbs
  2375.     tst.l    d0
  2376.     bne.b    .got
  2377.  
  2378.     ; die horribe death
  2379.     move.l    #AT_DeadEnd!AG_NoMemory,d7
  2380.     call    Alert
  2381. .got
  2382.  
  2383.     ; initialize EXTRES API...
  2384.  
  2385.     moveq    #BKERHSS_SIZEOF,d0
  2386.     moveq    #MEMF_ANY,d1
  2387.     call    AllocMem
  2388.     tst.l    d0
  2389.     beq.b    .nomem
  2390.  
  2391.     move.l    d0,-(sp)
  2392.     move.l    d0,a0
  2393.     call    InitSemaphore
  2394.     move.l    (sp)+,a1
  2395.     move.l    #ERH_API_V1,(BKERHSS_version,a1)
  2396.     clr.w    (BKERHSS_unused0,a1)
  2397.  
  2398.     ; must not optimize this!
  2399. _erh_memheader    EQU    *+2
  2400.     move.l    #0,(BKERHSS_memheader,a1)
  2401.  
  2402.     lea    (_erh_name,pc),a0
  2403.     move.l    a0,(LN_NAME,a1)
  2404.     move.b    #-120,(LN_PRI,a1)
  2405.  
  2406.     call    AddSemaphore
  2407. .nomem
  2408.     ; fall in!
  2409.     ;bsr.b    MoveChipHeader
  2410.     ;rts
  2411.  
  2412. ; Routines taken from FastExec 2.5 public domain source code by
  2413. ; Torbjörn A. Andersson. Modified by Harry Sintonen.
  2414. ******************************************************************************
  2415.  
  2416. MoveChipHeader    movem.l    d2/a2-a3,-(sp)
  2417.     call    Forbid
  2418.  
  2419. .loop0    move.l    (MemList,a6),d2
  2420.  
  2421. .loop1    move.l    d2,a2
  2422.     move.l    (a2),d2
  2423.     beq.b    .quit
  2424.  
  2425.     cmp.l    #$1000000,a2        ; address
  2426.     bhs.b    .loop1
  2427.  
  2428.     moveq    #MH_SIZE,d0
  2429.     moveq    #MEMF_PUBLIC!MEMF_FAST,d1
  2430.     call    AllocMem
  2431.     tst.l    d0
  2432.     beq.b    .quit
  2433.     move.l    d0,a3
  2434.  
  2435.     lea    (LN_TYPE,a2),a0        ; source
  2436.     lea    (LN_TYPE,a3),a1        ; dest
  2437.     moveq    #MH_SIZE-LN_TYPE,d0
  2438.     call    CopyMem
  2439.  
  2440.     lea    (MH_SIZE,a2),a0
  2441.     cmp.l    (MH_LOWER,a2),a0
  2442.     bne.b    .ok
  2443.     move.l    a2,(MH_LOWER,a3)
  2444. .ok
  2445.     move.l    a2,a1            ; node
  2446.     call    Remove
  2447.     lea    (MemList,a6),a0        ; list
  2448.     move.l    a3,a1            ; node
  2449.     call    Enqueue
  2450.  
  2451. ;    cmp.w    #36,(LIB_VERSION,a6)
  2452. ;    blo.b    .loop0
  2453.  
  2454.     move.l    a2,a1            ; memoryBlock
  2455.     moveq    #MH_SIZE,d0
  2456.  
  2457.     move.l    d0,d1
  2458.     add.l    a1,d1
  2459.     lea    (MemList,a6),a0
  2460. .floop    move.l    (a0),a0
  2461.     tst.l    (a0)
  2462.     beq.b    .fdone
  2463.     cmp.l    (MH_LOWER,a0),a1
  2464.     blo.b    .floop
  2465.     cmp.l    (MH_UPPER,a0),a1
  2466.     bhs.b    .floop
  2467.     cmp.l    (MH_UPPER,a0),d1
  2468.     bhi.b    .fdone
  2469.     call    FreeMem
  2470. .fdone    bra.b    .loop0
  2471.  
  2472. .quit    call    Permit
  2473.     movem.l    (sp)+,d2/a2-a3
  2474.     rts
  2475.  
  2476. _erh_name    dc.b    'EXTRES Handler',0
  2477.     CNOP    0,2
  2478. _erhandler_end
  2479. ERHANDLER_SIZEOF EQU    (*-_erhandler_module+7)&-8
  2480.  
  2481.  
  2482. CacheClearOS    movem.l    d0-d1/a0-a1/a6,-(sp)
  2483.     pea    (.cleanexit,pc)
  2484.     move.l    (_ExecBase,pc),a6
  2485.     cmp.w    #37,(LIB_VERSION,a6)
  2486.     blo.b    CacheClear
  2487.     jmp    (_LVOCacheClearU,a6)    OK! ;-)
  2488. .cleanexit    movem.l    (sp)+,d0-d1/a0-a1/a6
  2489.     rts
  2490. CacheClear    btst    #AFB_68020,(_AttnFlags+1,pc)
  2491.     beq.b    .no68020
  2492.     movem.l    a5/a6,-(sp)
  2493.     lea    (.cacheclrsv,pc),a5
  2494.     move.l    (_ExecBase,pc),a6
  2495.     call    Supervisor
  2496.     movem.l    (sp)+,a5/a6
  2497. .no68020    rts
  2498. .cacheclrsv    or.w    #$700,sr        Disable interrupts
  2499.     bsr.b    CacheClrS
  2500.     nop
  2501.     rte
  2502. CacheClrS    btst    #AFB_68040,(_AttnFlags+1,pc)
  2503.     beq.b    .not040
  2504.     CACHEFLUSH040
  2505.     rts
  2506. .not040    move.l    d0,-(sp)
  2507.     movec    cacr,d0
  2508.     or.w    #CACRF_ClearI!CACRF_ClearD,d0
  2509.     movec    d0,cacr
  2510.     move.l    (sp)+,d0
  2511.     rts
  2512.  
  2513. DisableCache    btst    #AFB_68020,(_AttnFlags+1,pc)
  2514.     beq.b    .no68020
  2515.     movem.l    a5/a6,-(sp)
  2516.     lea    (.discachesv,pc),a5
  2517.     move.l    (_ExecBase,pc),a6
  2518.     call    Supervisor
  2519.     movem.l    (sp)+,a5/a6
  2520. .no68020    rts
  2521. .discachesv    or.w    #$700,sr        Disable interrupts
  2522.     bsr.b    DisableCacheS
  2523.     nop
  2524.     rte
  2525. DisableCacheS    move.l    d0,-(sp)
  2526.     movec    cacr,d0
  2527.  
  2528.     btst    #AFB_68040,(_AttnFlags+1,pc)
  2529.     bne.b    .is040
  2530.  
  2531.     and.w    #~(CACRF_EnableI!CACRF_IBE!CACRF_EnableD!CACRF_DBE),d0
  2532.     or.w    #CACRF_ClearI!CACRF_ClearD,d0
  2533.     bra.b    .exit
  2534. .is040
  2535.     BITDEF    CACR,HalfICache,13        ;060
  2536.     BITDEF    CACR,NoAllocateI,14        ;040/060
  2537.     BITDEF    CACR,EnableICache,15        ;040/060
  2538.     BITDEF    CACR,ClearUserBCache,21        ;060
  2539.     BITDEF    CACR,ClearAllBCache,22        ;060
  2540.     BITDEF    CACR,EnableBCache,23        ;060
  2541.     BITDEF    CACR,HalfDCache,27        ;060
  2542.     BITDEF    CACR,DisableCPUSHInv,28        ;060?
  2543.     BITDEF    CACR,EnableStoreBuffer,29    ;060
  2544.     BITDEF    CACR,NoAllocateD,30        ;040/060
  2545.     BITDEF    CACR,EnableDCache,31        ;040/060
  2546.  
  2547. CACRF_CachesOr040    EQU    CACRF_EnableDCache|CACRF_EnableICache
  2548. CACRF_CachesAnd040    EQU    CACRF_NoAllocateI|CACRF_NoAllocateD
  2549. CACRF_CachesOr060    EQU    CACRF_CachesOr040|CACRF_EnableStoreBuffer|CACRF_EnableBCache
  2550. CACRF_CachesAnd060    EQU    CACRF_CachesAnd040|CACRF_DisableCPUSHInv|CACRF_HalfICache|CACRF_HalfDCache
  2551.  
  2552.     BITDEF    PCR,EnableDebugFeatures,7    ;060
  2553.     BITDEF    PCR,DisableFPU,1        ;060
  2554.     BITDEF    PCR,EnableSuperScalar,0        ;060
  2555.  
  2556.     and.l    #~CACRF_CachesOr060,d0
  2557.     or.l    #CACRF_ClearAllBCache,d0
  2558.     nop
  2559.     dc.w    $F4F8            CPUSHA    BC
  2560.     nop
  2561. .exit    movec    d0,cacr
  2562.     move.l    (sp)+,d0
  2563.     rts
  2564.  
  2565. ; IN: a1=libname, d0=version, a6=execbase
  2566. FindLib    bsr.b    OpenLib
  2567.     beq.b    .exit
  2568.     move.l    d0,-(sp)
  2569.     move.l    d0,a1
  2570.     call    CloseLibrary
  2571.     move.l    (sp)+,d0
  2572. .exit    rts
  2573. ; IN: a1=libname, d0=version, a6=execbase
  2574. OpenLib    move.w    #_LVOOldOpenLibrary,d1
  2575.     cmp.w    #33,(LIB_VERSION,a6)
  2576.     blo.b    .oldol
  2577.     move.w    #_LVOOpenLibrary,d1
  2578. .oldol    jsr    0(a6,d1.w)
  2579.     tst.l    d0
  2580.     rts
  2581.  
  2582.  
  2583. ;  IN: a0=filename (d6=dosbase, _Printf)
  2584. ; OUT: a1=buffer, d0=buffer len, d1=file len
  2585.  
  2586. XPKLoad    movem.l    d2-d7/a2-a6,-(sp)
  2587.     move.l    a0,a3
  2588.     sub.l    a5,a5
  2589.     moveq    #0,d6
  2590.     moveq    #0,d7
  2591.  
  2592.     move.l    (4*4,sp),a6
  2593.     move.l    a3,d1
  2594. ;;    moveq    #ACCESS_READ,d2
  2595. ;;    call    Lock
  2596. ;;    move.l    d0,d1
  2597.     bsr    _lockread
  2598.  
  2599.     beq    .exit
  2600.     move.l    d1,-(sp)
  2601.     lea    (-(fib_SIZEOF+4),sp),sp
  2602.     move.l    sp,d2
  2603.     addq.l    #3,d2
  2604.     and.w    #-4,d2
  2605.     call    Examine
  2606.     move.l    d2,a0
  2607.     move.l    (fib_Size,a0),d3
  2608.     move.l    d0,d2
  2609.     lea    ((fib_SIZEOF+4),sp),sp
  2610.     move.l    (sp)+,d1
  2611.     call    UnLock
  2612.     tst.l    d2
  2613.     beq.b    .exit
  2614.  
  2615.     move.l    a3,d1
  2616.     move.l    #MODE_OLDFILE,d2
  2617.     call    Open
  2618.     move.l    d0,d5
  2619.     beq.b    .exit
  2620.  
  2621.     move.l    d5,d1
  2622.     subq.l    #4,sp
  2623.     move.l    sp,d2
  2624.     move.l    d3,-(sp)
  2625.     moveq    #4,d3
  2626.     call    Read
  2627.     move.l    (sp)+,d3
  2628.     move.l    (sp)+,d4
  2629.     subq.l    #4,d0
  2630.     bne.b    .exit
  2631.     move.l    d5,d1
  2632.     moveq    #0,d2
  2633.     move.l    d3,-(sp)
  2634.     moveq    #OFFSET_BEGINNING,d3
  2635.     call    Seek
  2636.     move.l    (sp)+,d3
  2637.     subq.l    #4,d0
  2638.     bne.b    .exit
  2639.     cmp.l    #'XPKF',d4
  2640.     beq.b    .tryxpk
  2641.  
  2642. .noxpk    move.l    (_ExecBase,pc),a6
  2643.     move.l    d3,d0
  2644.     moveq    #MEMF_PUBLIC,d1
  2645.     call    AllocMem
  2646.     move.l    (4*4,sp),a6
  2647.     move.l    d0,d2
  2648.     beq.b    .close
  2649.  
  2650.     move.l    d5,d1
  2651.     call    Read
  2652.     cmp.l    d0,d3
  2653.     bne.b    .free
  2654.  
  2655.     move.l    d3,d7
  2656.     move.l    d3,d6
  2657.     move.l    d2,a5
  2658.     bra.b    .close
  2659.  
  2660. .free    move.l    (_ExecBase,pc),a6
  2661.     move.l    d2,a1
  2662.     move.l    d3,d0
  2663.     call    FreeMem
  2664.     move.l    (4*4,sp),a6
  2665.  
  2666. .close    move.l    d5,d1
  2667.     call    Close
  2668.  
  2669. .exit    move.l    a5,a1
  2670.     move.l    d6,d0
  2671.     move.l    d7,d1
  2672.     movem.l    (sp)+,d2-d7/a2-a6
  2673.     rts
  2674.  
  2675.  
  2676. .tryxpk    move.l    (_ExecBase,pc),a6
  2677.     lea    (.xpkname,pc),a1
  2678.     moveq    #0,d0
  2679.     bsr    OpenLib
  2680.     beq    .noxpk
  2681.     move.l    d0,d2
  2682.  
  2683.     move.l    (4*4,sp),a6
  2684.     move.l    d5,d1
  2685.     call    Close
  2686.     exg    d2,a6
  2687.  
  2688. XPKERRSIZE    EQU    ((XPKERRMSGSIZE+1+3)&-4)
  2689.  
  2690.     lea    (-XPKERRSIZE,sp),sp
  2691.     move.l    sp,a4
  2692.     clr.l    -(sp)
  2693.     move.l    sp,d3
  2694.     clr.l    -(sp)
  2695.     move.l    sp,d4
  2696.     clr.l    -(sp)
  2697.     move.l    sp,d5
  2698.     clr.l    -(sp)
  2699.     moveq    #-1,d0
  2700.     move.l    d0,-(sp)
  2701.     pea    XPK_PassThru        Allow uncompressed file
  2702.     pea    MEMF_PUBLIC
  2703.     pea    XPK_OutMemType
  2704.     move.l    d5,-(sp)        buflen
  2705.     pea    XPK_GetOutBufLen
  2706.     move.l    d4,-(sp)        filelen
  2707.     pea    XPK_GetOutLen
  2708.     move.l    d3,-(sp)        outbuf
  2709.     pea    XPK_GetOutBuf
  2710.     move.l    a4,-(sp)        errbuf
  2711.     pea    XPK_GetError
  2712.     move.l    a3,-(sp)
  2713.     pea    XPK_InName
  2714.     move.l    sp,a0
  2715.     call    XpkUnpack
  2716.     move.l    d5,sp
  2717.  
  2718.     move.l    (sp)+,d6        d6=buflen
  2719.     move.l    (sp)+,d7        d7=filelen
  2720.     move.l    (sp)+,a5        a5=outbuf
  2721.  
  2722.     tst.l    d0
  2723.     beq.b    .allok
  2724.     ; a4=errbuf
  2725.     move.l    a4,a0
  2726. .finde    tst.b    (a0)+
  2727.     bne.b    .finde
  2728.     move.b    #10,(-1,a0)
  2729.     clr.b    (a0)
  2730.     move.l    a4,a0
  2731.     exg    d2,d6
  2732.     bsr    _Printf
  2733.     exg    d2,d6
  2734.  
  2735. .allok    lea    (XPKERRSIZE,sp),sp
  2736.  
  2737.     move.l    a6,a1
  2738.     move.l    (_ExecBase,pc),a6
  2739.     call    CloseLibrary
  2740.     bra    .exit
  2741.  
  2742.  
  2743. .xpkname    dc.b    'xpkmaster.library',0
  2744.     CNOP    0,2
  2745.  
  2746.  
  2747.  
  2748.  
  2749.  
  2750. ;  IN: a0=rom, d0=rom len
  2751. ; OUT: d0=success (number of patches done, or zero)
  2752. LastPatches    movem.l    d1-a6,-(sp)
  2753.     moveq    #0,d7
  2754.     move.l    a0,a6
  2755.     move.l    d0,d6
  2756.  
  2757. SUPERVISOR_NOREVERSE    SET    0
  2758.     IFNE    SUPERVISOR_NOREVERSE
  2759.     move.w    #2048/2-1,d0        during first 2k
  2760.     move.l    #$2D40003A,d1
  2761. .scan    addq.l    #2,a0
  2762.     cmp.l    (a0),d1
  2763.     dbeq    d0,.scan
  2764.     tst.w    d0
  2765.     bmi.b    .not0
  2766.     cmp.l    #$6608223C,(4,a0)
  2767.     bne.b    .scan
  2768.     cmp.l    #MEMF_CLEAR!MEMF_REVERSE,(8,a0)
  2769.     bne.b    .scan
  2770.     cmp.w    #$60EC,(12,a0)
  2771.     bne.b    .scan
  2772.  
  2773.     move.w    #MEMF_CLEAR>>16,(8,a0)
  2774.     addq.l    #1,d7
  2775. .not0
  2776.     ENDC
  2777.  
  2778.     move.l    (_OrigSum,pc),d5
  2779.     cmp.l    ROMSUMOFFS(a6,d6.l),d5
  2780.     bne    .not_correct_chksum
  2781.  
  2782.     cmp.l    #33<<16!180,($C,a6)
  2783.     bne.b    .not_33180
  2784.     cmp.l    #$56F2E2A6,d5        Must be original to patch!
  2785.     bne.b    .not_33180
  2786.  
  2787.     move.w    #$0020,($19C,a6)    2MB chip ram
  2788.     move.l    #$FF000001,($3000,a6)    ExecBase address mask
  2789.  
  2790.     IFGT    0
  2791.     move.l    #$20482249,d0        move.l a0,a0 / move.l a1,a1
  2792.     move.l    d0,($4D9A,a6)        expansion.library bug
  2793.     move.l    #$4EAEFF3A,($4D9A+4,a6)
  2794.     move.l    #$4A80672E,($4D9A+8,a6)
  2795.     move.l    #$24002200,($4D9A+12,a6)
  2796.     move.l    #$20434280,($4D9A+16,a6)
  2797.     move.l    #$302F0002,($4D9A+20,a6)
  2798.     move.w    d0,($4D9A+24,a6)
  2799.     ENDC
  2800.  
  2801.     move.l    #$20482249,d0        move.l a0,a0 / move.l a1,a1
  2802.     move.w    d0,($4D9A,a6)        expansion.library bug
  2803.     move.l    d0,($4D9A+2,a6)
  2804.     move.l    #$4A80672C,($4DA4,a6)
  2805.     move.l    #$24002240,($4DA4+4,a6)
  2806.     move.l    #$20437000,($4DA4+8,a6)
  2807.     move.b    #$30,($4DA4+12,a6)
  2808.  
  2809.     ; my:
  2810.     move.l    #$99CC4ED5,($1E6,a6)    no $C00000 mem, please !!
  2811. ;;    clr.b    ($56D,a6)        disable cache (instruction)
  2812.  
  2813.     addq.l    #1,d7
  2814. .not_33180
  2815.  
  2816.     cmp.l    #34<<16!5,($C,a6)
  2817.     bne.b    .not_3405
  2818.     cmp.l    #$15267DB3,d5        Must be original to patch!
  2819.     bne.b    .not_3405
  2820.  
  2821.     move.w    #$0020,($19C,a6)    2MB chip ram
  2822.     move.l    #$FF000001,($303C,a6)    ExecBase address mask
  2823.  
  2824.     addq.l    #1,d7
  2825. .not_3405
  2826.  
  2827. .not_correct_chksum
  2828.  
  2829.     move.l    d7,d0
  2830.     movem.l    (sp)+,d1-a6
  2831.     rts
  2832.  
  2833.  
  2834. ;  IN: a0=rom, d0=rom len
  2835. ; OUT: d0=success (number of patches done, or zero)
  2836. SpeedROM    movem.l    d1-a6,-(sp)
  2837.  
  2838.     moveq    #0,d7
  2839.     move.l    a0,a2
  2840.     move.l    d0,d4
  2841.     move.l    #$01000000,d2
  2842.     sub.l    d4,d2
  2843.     move.l    a2,a5
  2844.     sub.l    d2,a5            a5=difference
  2845.  
  2846.     move.l    (4,a2),a1
  2847.     add.l    a5,a1
  2848.  
  2849.     cmp.w    #$203C,(6,a1)        KS 1.x start: (34.5)
  2850.     bne.b    .nosp1
  2851.     cmp.l    #$53806EFC,(12,a1)
  2852.     bne.b    .nosp1
  2853.     move.w    #$6008,(6,a1)
  2854.     addq.l    #1,d7
  2855. .nosp1
  2856.     IFEQ    KEEP_CHECKSUM
  2857.     cmp.l    #$41F900F8,(4,a1)    KS 3.0 chksum:
  2858.     bne.b    .nosp2
  2859.     cmp.l    #$72FF7401,(10,a1)
  2860.     bne.b    .nosp2
  2861.     move.l    #$7AFF6010,(10,a1)
  2862.     addq.l    #1,d7
  2863. .nosp2
  2864.     cmp.l    #$41FAFF28,(4,a1)    KS 3.1 chksum:
  2865.     bne.b    .nosp3
  2866.     cmp.l    #$72FF7401,(8,a1)
  2867.     bne.b    .nosp3
  2868.     move.l    #$7AFF6010,(8,a1)
  2869.     addq.l    #1,d7
  2870. .nosp3
  2871.     ENDC
  2872.  
  2873.     ; Reconnect resident modules:
  2874.  
  2875.     moveq    #-(RT_SIZE+2),d1
  2876.     move.l    a2,a0
  2877.     add.l    d4,d1
  2878.     sub.l    a1,a1
  2879. .find    subq.l    #2,d1
  2880.     bls.b    .done
  2881.     cmp.w    #RTC_MATCHWORD,(a0)+
  2882.     bne.b    .find
  2883.     moveq    #2,d0
  2884.     add.l    (a0),d0            (RT_MATCHTAG-2,a0),d0
  2885.     add.l    a5,d0
  2886.     cmp.l    a0,d0
  2887.     bne.b    .find
  2888.     subq.l    #2,a0
  2889.     move.l    a1,d0
  2890.     beq.b    .is_1st
  2891.     move.l    a0,d0
  2892.     sub.l    a5,d0
  2893.     move.l    d0,(RT_ENDSKIP,a1)
  2894. .is_1st    move.l    a0,a1
  2895.     lea    (RT_SIZE,a0),a0
  2896.     bra.b    .find
  2897. .done
  2898.     move.l    a1,d0
  2899.     beq.b    .none
  2900.     ; make last RT_ENDSKIP point $FFFFFE
  2901.     move.l    #$FFFFFE,(RT_ENDSKIP,a1)
  2902. .none
  2903.  
  2904.     ; can't really reconnect EXTRES buffer restags
  2905.     ; ...
  2906.  
  2907.     addq.l    #1,d7
  2908.  
  2909.     move.l    d7,d0
  2910.     movem.l    (sp)+,d1-a6
  2911.     rts
  2912.  
  2913.  
  2914.     IFGT    0
  2915.  
  2916. ; *** WARNING: REQUIRES SOURCE AND DESTINATION ADDRESSES ALIGNEG BY 16! ***
  2917.  
  2918. ;  IN: a0=source ptr
  2919. ;      a1=dest ptr
  2920. ;      d0=copy len, aligned by 256
  2921. ; OUT: a0=source ptr + copy len
  2922. ;      a1=dest ptr + copy len
  2923. ;      d0=copy len
  2924. copymem256_040    move.l    d0,-(sp)
  2925.     lsr.l    #8,d0            /256
  2926. .copy    move16    (a0)+,(a1)+        16
  2927.     move16    (a0)+,(a1)+        16
  2928.     move16    (a0)+,(a1)+        16
  2929.     move16    (a0)+,(a1)+        16
  2930.  
  2931.     move16    (a0)+,(a1)+        16
  2932.     move16    (a0)+,(a1)+        16
  2933.     move16    (a0)+,(a1)+        16
  2934.     move16    (a0)+,(a1)+        16
  2935.  
  2936.     move16    (a0)+,(a1)+        16
  2937.     move16    (a0)+,(a1)+        16
  2938.     move16    (a0)+,(a1)+        16
  2939.     move16    (a0)+,(a1)+        16
  2940.  
  2941.     subq.l    #1,d0
  2942.     move16    (a0)+,(a1)+        16
  2943.     move16    (a0)+,(a1)+        16
  2944.     move16    (a0)+,(a1)+        16
  2945.     move16    (a0)+,(a1)+        16
  2946.     bne.b    .copy
  2947.     move.l    (sp)+,d0
  2948.     rts
  2949.  
  2950.     ENDC
  2951.  
  2952.  
  2953. ;  IN: a0=source ptr
  2954. ;      a1=dest ptr
  2955. ;      d0=copy len, aligned by 256
  2956. ; OUT: a0=source ptr + copy len
  2957. ;      a1=dest ptr + copy len
  2958. ;      d0=copy len
  2959. copymem256    movem.l    d0-d7/a2-a6,-(sp)
  2960.     lsr.l    #8,d0            /256
  2961. .copy    movem.l    (a0)+,d1-d7/a2-a6
  2962.     movem.l    d1-d7/a2-a6,(a1)    12*4=48
  2963.     movem.l    (a0)+,d1-d7/a2-a6
  2964.     movem.l    d1-d7/a2-a6,(1*48,a1)    12*4=48
  2965.     movem.l    (a0)+,d1-d7/a2-a6
  2966.     movem.l    d1-d7/a2-a6,(2*48,a1)    12*4=48
  2967.     movem.l    (a0)+,d1-d7/a2-a6
  2968.     movem.l    d1-d7/a2-a6,(3*48,a1)    12*4=48
  2969.     movem.l    (a0)+,d1-d7/a2-a6
  2970.     movem.l    d1-d7/a2-a6,(4*48,a1)    12*4=48
  2971.     movem.l    (a0)+,d1-d4
  2972.     movem.l    d1-d4,(5*48,a1)        4*4=16
  2973.     subq.l    #1,d0
  2974.     lea    (256,a1),a1
  2975.     bne.b    .copy
  2976.     movem.l    (sp)+,d0-d7/a2-a6
  2977.     rts
  2978.  
  2979.     ;IFGT    (copymem256_000-copymem256)-$7E
  2980.     ;FAIL    "copymem256 offset out of bra.b!"
  2981.     ;ENDC
  2982.  
  2983.  
  2984. ;  IN: a4=rom buffer
  2985. ;      d3=rom size
  2986. KickSys    ;illegal
  2987.  
  2988.     lea    (_regtemp,pc),a0
  2989.     movem.l    d3/a4,(a0)
  2990.  
  2991.     move.l    (_ExecBase,pc),a6
  2992.     lea    (GfxName,pc),a1
  2993.     moveq    #0,d0
  2994.     bsr    FindLib
  2995.     move.l    d0,a2
  2996.     exg    a2,a6
  2997.     sub.l    a1,a1
  2998.     call    LoadView
  2999.     call    WaitTOF
  3000.     cmp.w    #39,(LIB_VERSION,a6)
  3001.     blo.b    .noaga
  3002.     btst    #GFXB_AA_ALICE,(gb_ChipRevBits0,a6)
  3003.     beq.b    .noaga
  3004.     lea    $DFF106,a0
  3005.     move.w    #$0C00,(a0)        Reset AGA hardware.
  3006.     move.w    #$0000,($1FC-$106,a0)
  3007. .noaga    call    WaitTOF
  3008.     exg    a2,a6
  3009.  
  3010.     move.b    (_CPUCard,pc),d0
  3011.     bne    .mapcpucard
  3012.  
  3013.     lea    (.super,pc),a0
  3014.     bra    runnommu
  3015.  
  3016. .super    ori.w    #$700,sr        Disable all ints!
  3017.     bsr    CacheClrS        flush caches
  3018.  
  3019.     movem.l    (_regtemp,pc),d3/a4
  3020.  
  3021.     bset    #7,$DE0002        Set Gary Coldstart
  3022.  
  3023.     move.b    (_B20x0,pc),d0
  3024.     beq.b    .noB20x0a
  3025.     movec    dfc,d5
  3026.     moveq    #3,d0            Entry FC for Control Registers
  3027.     movec    d0,dfc
  3028.     moveq    #0,d1            Turn shadow off:
  3029.     bsr    SetMemShadowN
  3030. .noB20x0a
  3031.     move.b    (_CSPPC_MK3,pc),d0
  3032.     bne.b    .also_CSPPC_MK3
  3033.     move.b    (_BlizPPC,pc),d0
  3034.     beq.b    .no_blizppc1
  3035.     clr.b    $F60013            Turn off BlizPPC maprom
  3036. .also_CSPPC_MK3    nop
  3037.     nop
  3038.     move.b    #$10,$F60000        blizzppc/csppc/mkiii
  3039.     nop                majik
  3040.     nop
  3041. .no_blizppc1
  3042.     move.l    (_BlizROM,pc),a1
  3043.  
  3044.     move.l    #$80000,d0
  3045.     cmp.l    d0,d3
  3046.     bhs.b    .no1st
  3047.  
  3048.     move.l    d3,d0            Copy 256k:
  3049.     move.l    a4,a0
  3050.     bsr    copymem256
  3051. .no1st
  3052.     move.l    d3,d0            Copy ROM:
  3053.     move.l    a4,a0
  3054.     bsr    copymem256
  3055.  
  3056.     move.b    (_B20x0,pc),d0
  3057.     beq.b    .noB20x0b
  3058.     moveq    #1,d1            Turn shadow back on:
  3059.     bsr    SetMemShadowN
  3060.     movec    d5,dfc
  3061.     bsr    _fullflush040
  3062. .noB20x0b
  3063.     bsr    DisableCacheS        Disable all caches.
  3064.  
  3065.     move.b    (_MK2,pc),d0
  3066.     beq.b    .no_mk2
  3067.     move.b    #$2A,$880000E3        Trigger MKII maprom
  3068.     nop
  3069.     bra.b    .doreset
  3070. .no_mk2
  3071.     move.b    (_CSPPC_MK3,pc),d0
  3072.     beq.b    .no_CSPPC_MK3
  3073.  
  3074.     move.l    (_tc,pc),d0        restore mmu state for
  3075.     movec    d0,tc            a while...
  3076.     nop
  3077.  
  3078.     lea    $00F60020,a0        Trigger PPC/MKIII maprom
  3079.     move.b    #$60,(a0)
  3080.     nop
  3081.     move.b    #$50,(a0)
  3082.     nop
  3083.     move.b    #$30,(a0)
  3084.     nop
  3085.     move.b    #1,(-8,a0)
  3086.     nop
  3087.     clr.b    (a0)
  3088.     bra.b    .also_CSPPC_MK3b
  3089. .no_CSPPC_MK3
  3090.     move.b    (_BlizPPC,pc),d0
  3091.     beq.b    .no_blizppc2
  3092.  
  3093.     move.l    (_tc,pc),d0        restore mmu state for
  3094.     movec    d0,tc            a while
  3095.     nop
  3096.  
  3097.     clr.b    $F60012            Trigger BlizPPC maprom
  3098. .also_CSPPC_MK3b
  3099.     nop
  3100.     nop
  3101.     move.b    #$40,$F60018        blizzppc/csppc/mkiii
  3102.     move.b    #$0C,$F60000        majik
  3103.     nop
  3104.     nop
  3105.  
  3106.     movec    tc,d0            disable MMU again
  3107.     and.w    #$7FFF,d0
  3108.     movec    d0,tc
  3109.     nop
  3110. .no_blizppc2
  3111.  
  3112. .doreset    moveq    #-1,d0            Trash execbase:
  3113.     move.l    d0,(4).w
  3114.     bsr    CacheClrS        flush caches
  3115.  
  3116.     lea    $DFF09A,a0
  3117.     move.w    #$4000,(a0)+        All interrupts off
  3118.     move.w    #$3FFF,(a0)+        All DMA off
  3119.  
  3120.     nop
  3121.  
  3122.     lea    $01000000+4,a0        ...and reboot...
  3123.     sub.l    (ROMSIZEOFFS-4,a0),a0
  3124.     move.l    (a0),a0
  3125.     subq.l    #2,a0
  3126.     IFGT    (Main-*)&2        Main must be longword aligned!
  3127.     move.l    a1,a1
  3128.     ENDC
  3129. .reset    reset
  3130.     jmp    (a0)
  3131.  
  3132.  
  3133.  
  3134. .mapcpucard    call    Forbid            Must be V37+ if got here
  3135.     bsr.b    cachecontroli
  3136.  
  3137.     lea    (.nommucpuc,pc),a0
  3138.     bra    runnommu
  3139.  
  3140. .nommucpuc    ori.w    #$700,sr        Lock All Irqs
  3141.  
  3142.     movem.l    (_regtemp,pc),d3/a4
  3143.  
  3144.     clr.b    $DE0000            Gary bootflags=ColdStart
  3145.     clr.b    $DE0001
  3146.     nop
  3147.     move.l    #1,$80F80000        Trigger maprom
  3148.     nop
  3149.  
  3150.     move.l    a4,a0            a0=ptr to ROM Image
  3151.     move.l    #$07F80000,a1        Copy ROM Image
  3152.     move.l    #$80000,d0
  3153.     bsr    copymem256
  3154.  
  3155.     move.b    #$80,$DE0000        Gary BootFlag=ColdBoot
  3156.     move.b    #$80,$DE0001
  3157.  
  3158.     bra    .doreset
  3159.  
  3160.  
  3161. cachecontroli    moveq    #CACRF_EnableI!CACRF_IBE,d0
  3162. cachecontrol    move.l    #~CACRF_WriteAllocate,d1
  3163.     jmp    (_LVOCacheControl,a6)
  3164.  
  3165.  
  3166.     IFGT    0
  3167. ;  IN: -
  3168. ; OUT: d0,cc=nonzero if CPU Card with MAPROM present, else zero
  3169. CheckCPUCard    movem.l    d7/a6,-(sp)
  3170.     moveq    #0,d7
  3171.     move.l    (_ExecBase,pc),a6
  3172.     cmp.w    #37,(LIB_VERSION,a6)
  3173.     blo.b    .exit
  3174.     call    Forbid
  3175.  
  3176.     bsr.b    cachecontroli
  3177.     move.l    d0,-(sp)
  3178.  
  3179.     lea    (.nommu,pc),a0
  3180.     bsr    runnommu
  3181.     move.l    d0,d7
  3182.  
  3183.     move.l    (sp)+,d0
  3184.     bsr.b    cachecontrol
  3185.  
  3186.     call    Permit
  3187. .exit    move.l    d7,d0
  3188.     movem.l    (sp)+,d7/a6
  3189.     rts
  3190.  
  3191. .nommu    ori.w    #$700,sr        Lock All Irqs
  3192.     moveq    #0,d2
  3193.     clr.b    $DE0000            Gary bootflags=ColdStart
  3194.     clr.b    $DE0001
  3195.     nop
  3196.     move.l    #1,$80F80000        Trigger maprom
  3197.     nop
  3198.     move.l    $07F80000,d0        Test MAPROM
  3199.     cmp.l    $00F80000,d0
  3200.     bne.b    .nomap
  3201.     move.l    d0,d1            2nd test
  3202.     not.l    d1
  3203.     move.l    d1,$07F80000
  3204.     cmp.l    $F80000,d1
  3205.     beq.b    .does_map
  3206. .xit    move.l    d0,$07F80000
  3207. .nomap    move.b    #$80,$DE0000        Gary bootflags=Warmstart
  3208.     move.l    d2,d0
  3209.     rts
  3210.  
  3211. .does_map    moveq    #1,d2
  3212.     bra.b    .xit
  3213.     ENDC
  3214.  
  3215.  
  3216. _gettc    movec    tc,d0            $4e7a0003
  3217.     rte
  3218.  
  3219.  
  3220.  
  3221. mmuname    dc.b    'mmu.library',0
  3222. DosName    dc.b    'dos.library',0
  3223. _mmuflag    EQU    *-1
  3224. GfxName    dc.b    'graphics.library',0
  3225.     dc.b    '$VER:'
  3226. _Version    dc.b    'BlizKick 1.22 (3.2.00)',0
  3227.     dc.b    '$COPYRIGHT:'
  3228. _Copyright    dc.b    'Copyright © 1996-2000 PitPlane Productions',0
  3229. _Template    dc.b    'KICKFILE,MODULE/M,EXTRESBUF/N,SANITY/K/N,FORCE/S,'
  3230.     dc.b    'QUICKBOOT/S,SPEEDROM/S,HOGWAITBLIT/S,'
  3231.     dc.b    'CPUCARD=CSMKI/S,QUIET/S',0
  3232. _13Help    dc.b    'Usage: BlizKick ',$9b,'1mKICKFILE',$9b,'0m',10
  3233.     dc.b    'KICKFILE is full path for the ROM image to kick.',10,0
  3234. _ks13error    dc.b    'DOS Error #%ld!',10,0
  3235.     IFD    NEW_ENV_METHOD
  3236. _VarEnvArcName    dc.b    'ENVARC:'
  3237. _VarName    dc.b    'BKMODPATH',0
  3238.     ELSE
  3239. _EnvName    dc.b    'ENVx',0
  3240. _EnvArcName    dc.b    'ENVARC:',0
  3241. _VarName    dc.b    'BKMODPATH',0
  3242.     ENDC
  3243.  
  3244. RequiresBliz    dc.b    'BlizKick requires turbo board/CPU-card with MAPROM feature.',10,0
  3245. NoCPUCard    dc.b    'Couldn''t find CPU Card!',10,0
  3246. PlantError    dc.b    'Couldn''t plant module ''%s''!',10,0
  3247. Messu    dc.b    'Phase5 turbo board MapROM tool written by Harry "Piru" Sintonen.',10,0
  3248. Messu2    dc.b    'Kicking AMIGA ROM Operating System %d.%d.',10,0
  3249. Already    dc.b    'Kickstart is already kicked!',10,0
  3250. CouldNotKick    dc.b    'Couldn''t kick file ''%s''!',10,0
  3251. NoRem    dc.b    'Kickstart wasn''t kicked using BlizKick!',10,0
  3252.  
  3253.  
  3254.     CNOP    0,4
  3255. _Self    ds.l    1
  3256. _ExecBase    ds.l    1
  3257. _mmubase    ds.l    1
  3258. _Array    ds.l    10
  3259. _BlizROM    ds.l    1
  3260. _Quiet    ds.l    1
  3261. _OrigSum    ds.l    1
  3262. _regtemp    ds.l    2
  3263. _erh_alloclen    ds.l    1
  3264. _erh_freeaddr    ds.l    1
  3265. _erh_arealen    ds.l    1
  3266. _erh_areastart    ds.l    1
  3267. _tc    ds.l    1
  3268. _memhead    ds.b    MH_FIRST
  3269. _AttnFlags    ds.w    1
  3270. _MemHeaderFlag    ds.b    1
  3271. _B20x0    ds.b    1
  3272. _CPUCard    ds.b    1
  3273. _CSPPC_MK3    ds.b    1
  3274. _MK2    ds.b    1
  3275. _BlizPPC    ds.b    1
  3276.  
  3277. CODE_SIZEOF    EQU    (*-Main+7)&-8
  3278.  
  3279.     END
  3280.  
  3281.  
  3282. ; maprom not on:
  3283. ;
  3284. ; CS MKI     MH_UPPER & $80000 == 0
  3285. ; CS MKII    MH_UPPER & $80000 == 0
  3286. ; CS MKIII   MH_UPPER & $80000 == 0
  3287. ; CS PPC     MH_UPPER & $80000 != 0
  3288. ; BLIZZ PPC  MH_UPPER & $F0000 != 0
  3289. ;
  3290.  
  3291.  
  3292. ; model     id       mem     start     end        notes  maprom
  3293. ;turbo mem 2140/?    -        ?       - ?          A500
  3294. ; 1220     2140/0C   4 meg   $00200000-$00600000  A1200
  3295. ; 1230-I   2140/0?   ? meg   $????????-$????????  A1200  $????????
  3296. ; 1230-II  2140/0B   4 meg   $0E000000-$0E400000  A1200  $0FF80000 ! ??
  3297. ; 1230-II  2140/0B   8 meg   $????????-$????????  A1200  $1EF80000 ! ??
  3298. ; 1230-III 2140/0D   8 meg   $1DC00000-$1E400000  A1200  $1EF80000
  3299. ; 1230-III 2140/0D  32 meg   $1D000000-$1EF80000  A1200  $1EF80000
  3300. ; 1230-IV  2140/11   8 meg   $78000000-$78800000  A1200  $4FF80000
  3301. ; 1230-IV  2140/11   2 meg   $78000000-$78200000  A1200  $4FF80000?
  3302. ; 1230-IV  2140/11  16 meg   $68000000-$68F80000  A1200  $4FF80000?
  3303. ;?1260     2140/11   4 meg   $68000000-$68400000  A1200  $4FF80000 040&060 flag set!
  3304. ;>1260     2140/11   8 meg   $78000000-$78800000  A1200  $4FF80000 040&060 flag set!
  3305. ;?1260     2140/11  16 meg   $68000000-$69000000  A1200  $4FF80000 040&060 flag set!
  3306. ; 1260     2140/11   4 meg   $68000000-$68380000  A1200  $4FF80000? 040&060 flag set!
  3307. ; 1240-T   2140/11  16 meg   $68000000-$69000000  A1200  $4FF80000? 040 flag set!
  3308. ; 2040-ERC 2140/18   8 meg   $08000000-$08800000  A2000  $???????? 040 flag set!  'blizzard fastram'
  3309. ; 2060     2140/18  20 meg   $08000000-$09400000  A2000  $???????? 040&060 flag set!
  3310. ; 4030     2140/?    -        ?       - ?         A4000
  3311.  
  3312. ; CSMKI    2140/0C  32 meg   $08000000-$0A000000  A4000  csmagic  040 flag set
  3313. ; CSMKII   2140/19  80 meg   $08000000-$0D000000  A4000  csmagic
  3314. ; CS-PPC   2140/64   ? meg    ?       - ?         A4000 
  3315. ; BLIZPPC  2140/6E  16 meg   $68000000-$68800000  A1200  $FFF00000 040 flag set
  3316.  
  3317.  Board (unidentified):   Prod=8512/25($2140/$19) (@$EA0000 128K)
  3318.  Board (unidentified):   Prod=2092/18($82C/$12) (@$E90000 64K)
  3319.  Board (unidentified):   Prod=2167/201($877/$C9) (@$EC0000 64K)
  3320.  Board (unidentified):   Prod=8512/34($2140/$22) (@$40000000, size 64meg, subsize same)
  3321.  
  3322. last one is CV 64
  3323.  
  3324.  VERS:   Kickstart version 40.70, Exec version 40.10, Disk version 40.42
  3325.  RAM:    Node type $A, Attributes $505 (FAST), at $8000000-$CFFFFFF (80.0 meg)
  3326.  
  3327.  
  3328. *** CS MK I:
  3329.  
  3330. PROCESSOR:    CPU 68040/68882fpu
  3331. CUSTOM CHIPS:    AA PAL Alice (id=$0023), AA Lisa (id=$00F8)
  3332. VERS:    Kickstart version 39.106, Exec version 39.47, Disk version 39.29
  3333. RAM:    Node type $A, Attributes $505 (FAST), at $8000000-$9FFFFFF (32.0 meg)
  3334.     Node type $A, Attributes $703 (CHIP), at $2000-$1FFFFF (~2.0 meg)
  3335. BOARDS:
  3336. =======================================================================
  3337.  Board (unidentified):   Prod=2195/10($893/$A)
  3338.      (@$40000000, size 4meg, subsize same)
  3339.  ConfigDev structure found at location $27F8
  3340. ==== Board ID (ExpansionRom) information:
  3341. er_Manufacturer         =2195=$893=(~$F76C)
  3342. er_Product              =10=$A=(~$F5)
  3343. er_Type                 =$8F
  3344.   (type 2 (Zorro III), size 4meg, subsize same)
  3345.   (not for free list, no ROM diag vec, chained to next)
  3346. er_Flags                =$10
  3347.   (no space preference, can be shut up)
  3348. er_InitDiagVec          =$0
  3349. ==== Configuration (ConfigDev) information:
  3350. cd_BoardAddr            =$40000000
  3351. cd_BoardSize            =$1000000 (16384K)
  3352. cd_Flags                =$0  (CONFIGME bit cleared)
  3353. =======================================================================
  3354.  Board + ROM (HD?) (unidentified):   Prod=8512/12($2140/$C) (@$E90000 64K)
  3355.  ConfigDev structure found at location $2840
  3356. ==== Board ID (ExpansionRom) information:
  3357. er_Manufacturer         =8512=$2140=(~$DEBF)
  3358. er_Product              =12=$C=(~$F3)
  3359. er_Type                 =$D1
  3360.   (type 3, size 64K, not for free list, ROM diag vec valid, not chained)
  3361. er_Flags                =$0
  3362.   (no space preference, can be shut up)
  3363. er_InitDiagVec          =$80
  3364. DiagCopy at             =$8003320
  3365. ==== Configuration (ConfigDev) information:
  3366. cd_BoardAddr            =$E90000
  3367. cd_BoardSize            =$10000 (64K)
  3368. cd_Flags                =$0  (CONFIGME bit cleared)
  3369. =======================================================================
  3370.  Board + ROM (HD?) (unidentified):   Prod=2195/11($893/$B) (@$EA0000 64K)
  3371.  ConfigDev structure found at location $2888
  3372. ==== Board ID (ExpansionRom) information:
  3373. er_Manufacturer         =2195=$893=(~$F76C)
  3374. er_Product              =11=$B=(~$F4)
  3375. er_Type                 =$D1
  3376.   (type 3, size 64K, not for free list, ROM diag vec valid, not chained)
  3377. er_Flags                =$40
  3378.   (no space preference, can not be shut up)
  3379. er_InitDiagVec          =$0
  3380. ==== Configuration (ConfigDev) information:
  3381. cd_BoardAddr            =$EA0000
  3382. cd_BoardSize            =$10000 (64K)
  3383. cd_Flags                =$2  (CONFIGME bit still set)
  3384. =======================================================================
  3385.  Board (unidentified):   Prod=5000/1($1388/$1) (@$EB0000 64K)
  3386.  ConfigDev structure found at location $28D0
  3387. ==== Board ID (ExpansionRom) information:
  3388. er_Manufacturer         =5000=$1388=(~$EC77)
  3389. er_Product              =1=$1=(~$FE)
  3390. er_Type                 =$C1
  3391.   (type 3, size 64K, not for free list, no ROM diag vec, not chained)
  3392. er_Flags                =$40
  3393.   (no space preference, can not be shut up)
  3394. er_InitDiagVec          =$0
  3395. ==== Configuration (ConfigDev) information:
  3396. cd_BoardAddr            =$EB0000
  3397. cd_BoardSize            =$10000 (64K)
  3398. cd_Flags                =$0  (CONFIGME bit cleared)
  3399. =======================================================================
  3400.  Board + ROM (HD?) (unidentified):   Prod=2017/11($7E1/$B) (@$EC0000 64K)
  3401.  ConfigDev structure found at location $2918
  3402. ==== Board ID (ExpansionRom) information:
  3403. er_Manufacturer         =2017=$7E1=(~$F81E)
  3404. er_Product              =11=$B=(~$F4)
  3405. er_Type                 =$D1
  3406.   (type 3, size 64K, not for free list, ROM diag vec valid, not chained)
  3407. er_Flags                =$0
  3408.   (no space preference, can be shut up)
  3409. er_InitDiagVec          =$8000
  3410. ==== Configuration (ConfigDev) information:
  3411. cd_BoardAddr            =$EC0000
  3412. cd_BoardSize            =$10000 (64K)
  3413. cd_Flags                =$0  (CONFIGME bit cleared)
  3414. =======================================================================
  3415.  
  3416.  
  3417. ; Apollo:
  3418.  
  3419. ; 1230/28  2222/23   4 meg   $01C00000-02000000  A1200  none      030 flag set 'Apollo 32Bit Power'
  3420. ;                    8 meg   $03C00000-04400000 'Apollo 32Bit Power'
  3421. ; 1230/50  2222/23   4 meg   $01C00000-02000000  A1200  none      030 flag set 'Apollo 32Bit Power'
  3422. ; 1240/40  2222/23   4 meg   $01C00000-02000000  A1200  none      040 flag set '32Bit Power-Burstm'??
  3423. ; 1240     2222/23   8 meg   $01C00000-02400000  A1200  none      040 flag set '32Bit Power-Burstm'??
  3424. ; 1260     2222/23   4 meg   $01C00000-02000000  A1200  none      040&060 flag set '32Bit Power-Burstm'??
  3425. ; 4060     2222/23  32 meg   $08000000-0A000000  A4000  none      040&060 flag set 'Apollo 32Bit Power'
  3426.